Skip to content

Commit

Permalink
Revert "ltcgi android toggle"
Browse files Browse the repository at this point in the history
This reverts commit 9834476.
  • Loading branch information
z3y committed Jun 9, 2024
1 parent 320df57 commit 221b325
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 70 deletions.
21 changes: 6 additions & 15 deletions Editor/Importer/LitImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private string GetShaderLabCode(AssetImportContext ctx)


bool isAndroid = ctx.selectedBuildTarget == BuildTarget.Android;
bool ltcgiAllowed = LtcgiIncluded;
bool ltcgiAllowed = !isAndroid && LtcgiIncluded;
bool areaLitAllowed = !isAndroid && AreaLitIncluded;

AppendAdditionalDataToBlocks(isAndroid, shaderBlocks);
Expand Down Expand Up @@ -331,15 +331,8 @@ private string GetShaderLabCode(AssetImportContext ctx)

if (ltcgiAllowed)
{
if (isAndroid)
{
sb.AppendLine("#pragma shader_feature_local LTCGI_ANDROID");
}
else
{
sb.AppendLine("#pragma shader_feature_local LTCGI");
sb.AppendLine("#pragma shader_feature_local LTCGI_DIFFUSE_OFF");
}
sb.AppendLine("#pragma shader_feature_local LTCGI");
sb.AppendLine("#pragma shader_feature_local LTCGI_DIFFUSE_OFF");
}
if (areaLitAllowed)
{
Expand Down Expand Up @@ -626,7 +619,7 @@ private void AppendAdditionalDataToBlocks(bool isAndroid, ShaderBlocks shaderDat
shaderData.definesSb.AppendLine("#define BUILD_TARGET_PC");
}

if (!LtcgiIncluded)
if (isAndroid || !LtcgiIncluded)
{
shaderData.definesSb.AppendLine("#pragma skip_variants LTCGI");
shaderData.definesSb.AppendLine("#pragma skip_variants LTCGI_DIFFUSE_OFF");
Expand All @@ -650,11 +643,9 @@ private string GetDefaultPropertiesIncludeAfter(bool isAndroid)
defaultProps.AppendLine(GetPropertyDeclaration(settings.anisotropy, ShaderSettings.AnisotropyKeyword, "Anisotropy"));
defaultProps.AppendLine(GetPropertyDeclaration(settings.lightmappedSpecular, ShaderSettings.LightmappedSpecular, "Lightmapped Specular"));

if (LtcgiIncluded)
if (!isAndroid && LtcgiIncluded)
{
defaultProps.AppendLine(GetPropertyDeclaration(ShaderSettings.DefineType.LocalKeyword, "LTCGI", "LTCGI"));
defaultProps.AppendLine(GetPropertyDeclaration(ShaderSettings.DefineType.LocalKeyword, "LTCGI_ANDROID", "LTCGI Android"));

defaultProps.AppendLine(GetPropertyDeclaration(ShaderSettings.DefineType.LocalKeyword, "LTCGI", "Enable LTCGI"));
defaultProps.AppendLine(GetPropertyDeclaration(ShaderSettings.DefineType.LocalKeyword, "LTCGI_DIFFUSE_OFF", "Disable LTCGI Diffuse"));
}

Expand Down
64 changes: 13 additions & 51 deletions ShaderLibrary/ForwardLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,6 @@
#include "ACES.hlsl"
#endif

// the reason why this is used as an alternative to unity's dithering that is always present when there is post processing
// post processing doesnt handle black colors properly, especially visible with OLED displays, black colors are gray

// noise functions from xiexe https://github.com/Xiexe/PBR_Standard_Dithered_GSAA_SLO
// MIT License
// Copyright (c) 2018 Xiexe
// Copyright (c) 2018 TCL

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#define MOD3 float3(443.8975,397.2973, 491.1871)
float ditherNoiseFuncLow(float2 p)
{
float3 p3 = frac(float3(p.xyx) * MOD3 + _Time.y);
p3 += dot(p3, p3.yzx + 19.19);
return frac((p3.x + p3.y) * p3.z);
}
float3 ditherNoiseFuncHigh(float2 p)
{
float3 p3 = frac(float3(p.xyx) * (MOD3 + _Time.y));
p3 += dot(p3, p3.yxz + 19.19);
return frac(float3((p3.x + p3.y)*p3.z, (p3.x + p3.z)*p3.y, (p3.y + p3.z)*p3.x));
}

namespace CustomLighting
{

Expand Down Expand Up @@ -608,18 +569,19 @@ namespace CustomLighting
#endif

// #define FIX_BLACK_LEVEL
#if defined(UNITY_PASS_FORWARDBASE)
#ifdef DITHERING
finalColor.rgb -= ditherNoiseFuncHigh(unpacked.positionCS.xy / _ScreenParams.xy) * 0.001;
#endif
#if defined(FIX_BLACK_LEVEL) && !defined(SHADER_API_MOBILE)
// the reason why this exists is because post processing applies dithering additively with a noise in range [-1, 1]
// when applying dithering to 0 the visible range of the result is [0, 1]
// shifts the colors down one level so when the dithering gets applied black color will be in range [-2,0]
// doesnt fix color grading, it would require changes in post processing shaders
finalColor.rgb -= 0.0002;
#endif
#endif
// #if !defined(SHADER_API_MOBILE) && defined(UNITY_PASS_FORWARDBASE)
// #ifdef DITHERING
// finalColor.rgb -= ditherNoiseFuncHigh(input.uv01.xy) * 0.001;
// #else
// #ifdef FIX_BLACK_LEVEL
// // the reason why this exists is because post processing applies dithering additively with a noise in range [-1, 1]
// // when applying dithering to 0 the visible range of the result is [0, 1]
// // shifts the colors down one level so when the dithering gets applied black color will be in range [-2,0]
// // doesnt fix color grading, it would require changes in post processing shaders
// finalColor.rgb -= 0.0002;
// #endif
// #endif
// #endif

#ifdef USE_DEBUGCOLOR
return DebugColor.rgbb;
Expand Down
4 changes: 0 additions & 4 deletions ShaderLibrary/ShaderPass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
#define DISABLE_NONIMPORTANT_LIGHTS_PER_PIXEL
#endif

#ifdef LTCGI_ANDROID
#define LTCGI
#endif

#ifdef LTCGI_DIFFUSE_OFF
#define LTCGI_DIFFUSE_DISABLED
#undef LTCGI_DIFFUSE_OFF
Expand Down

0 comments on commit 221b325

Please sign in to comment.