From c218e2a1957520fe6e6a200e51d44aeaec93a3d3 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 6 Feb 2023 16:01:11 -0800 Subject: Shader now supports custom cubemap Applied to both PBS and TaSTT shaders. --- Shaders/PBS.shader | 3 +++ Shaders/PBS_lighting.cginc | 19 +++++++++++++++---- Shaders/TaSTT_lighting_template.cginc | 19 +++++++++++++++---- Shaders/TaSTT_template.shader | 3 +++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Shaders/PBS.shader b/Shaders/PBS.shader index ddcfd1f..e0b39da 100644 --- a/Shaders/PBS.shader +++ b/Shaders/PBS.shader @@ -12,6 +12,9 @@ BG_Emission_Mask("Background emission mask", 2D) = "black" {} BG_Emission_Color("Background emission color", Color) = (0, 0, 0) + [MaterialToggle] Enable_Custom_Cubemap("Enable custom cubemap", float) = 0 + Custom_Cubemap("Custom cubemap", Cube) = "" {} + // %TEMPLATE__UNITY_ROW_COL_PARAMS% } SubShader diff --git a/Shaders/PBS_lighting.cginc b/Shaders/PBS_lighting.cginc index d41d44b..13bde82 100644 --- a/Shaders/PBS_lighting.cginc +++ b/Shaders/PBS_lighting.cginc @@ -38,6 +38,9 @@ float4 BG_Metallic_ST; float4 BG_Smoothness_ST; float4 BG_Emission_Mask_ST; +float Enable_Custom_Cubemap; +UNITY_DECLARE_TEXCUBE(Custom_Cubemap); + void getVertexLightColor(inout v2f i) { #if defined(VERTEXLIGHT_ON) @@ -206,10 +209,18 @@ UnityIndirect GetIndirect(v2f i, float3 view_dir, float smoothness) { // There's a nonlinear relationship between mipmap level and roughness. float roughness = 1 - smoothness; roughness *= 1.7 - .7 * roughness; - float3 env_sample = UNITY_SAMPLE_TEXCUBE_LOD( - unity_SpecCube0, - reflect_dir, - roughness * UNITY_SPECCUBE_LOD_STEPS); + float3 env_sample; + if (Enable_Custom_Cubemap) { + env_sample = UNITY_SAMPLE_TEXCUBE_LOD( + Custom_Cubemap, + reflect_dir, + roughness * UNITY_SPECCUBE_LOD_STEPS); + } else { + env_sample = UNITY_SAMPLE_TEXCUBE_LOD( + unity_SpecCube0, + reflect_dir, + roughness * UNITY_SPECCUBE_LOD_STEPS); + } indirect.specular = env_sample; #endif diff --git a/Shaders/TaSTT_lighting_template.cginc b/Shaders/TaSTT_lighting_template.cginc index d2d4005..386a509 100644 --- a/Shaders/TaSTT_lighting_template.cginc +++ b/Shaders/TaSTT_lighting_template.cginc @@ -72,6 +72,9 @@ float Margin_Scale; float Margin_Rounding_Scale; float Enable_Margin_Effect_Squares; +float Enable_Custom_Cubemap; +UNITY_DECLARE_TEXCUBE(Custom_Cubemap); + // %TEMPLATE__CG_ROW_COL_CONSTANTS% float3 HUEtoRGB(in float H) @@ -398,10 +401,18 @@ UnityIndirect GetIndirect(v2f i, float3 view_dir, float smoothness) { // There's a nonlinear relationship between mipmap level and roughness. float roughness = 1 - smoothness; roughness *= 1.7 - .7 * roughness; - float3 env_sample = UNITY_SAMPLE_TEXCUBE_LOD( - unity_SpecCube0, - reflect_dir, - roughness * UNITY_SPECCUBE_LOD_STEPS); + float3 env_sample; + if (Enable_Custom_Cubemap) { + env_sample = UNITY_SAMPLE_TEXCUBE_LOD( + Custom_Cubemap, + reflect_dir, + roughness * UNITY_SPECCUBE_LOD_STEPS); + } else { + env_sample = UNITY_SAMPLE_TEXCUBE_LOD( + unity_SpecCube0, + reflect_dir, + roughness * UNITY_SPECCUBE_LOD_STEPS); + } indirect.specular = env_sample; #endif diff --git a/Shaders/TaSTT_template.shader b/Shaders/TaSTT_template.shader index db5d036..708300e 100644 --- a/Shaders/TaSTT_template.shader +++ b/Shaders/TaSTT_template.shader @@ -30,6 +30,9 @@ BG_Emission_Mask("Background emission mask", 2D) = "black" {} BG_Emission_Color("Background emission color", Color) = (0, 0, 0) + [MaterialToggle] Enable_Custom_Cubemap("Enable custom cubemap", float) = 0 + Custom_Cubemap("Custom cubemap", Cube) = "" {} + _Font_0x0000_0x1FFF ("_Font 0 (unicode 0x0000 - 0x1FFFF)", 2D) = "white" {} _Font_0x2000_0x3FFF ("_Font 1 (unicode 0x2000 - 0x3FFFF)", 2D) = "white" {} _Font_0x4000_0x5FFF ("_Font 2 (unicode 0x4000 - 0x5FFFF)", 2D) = "white" {} -- cgit v1.2.3