summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x3ner.shader3
-rwxr-xr-xScripts/Impostors.cs39
-rwxr-xr-xglobals.cginc4
-rwxr-xr-ximpostor.cginc7
4 files changed, 37 insertions, 16 deletions
diff --git a/3ner.shader b/3ner.shader
index d7663ef..dce0e18 100755
--- a/3ner.shader
+++ b/3ner.shader
@@ -382,8 +382,7 @@ Shader "yum_food/3ner"
[ThryToggle(_IMPOSTORS)] _Impostors_Enabled("Enable", Float) = 0
_Impostors_Atlas("Atlas", 2D) = "white" {}
_Impostors_Normal_Atlas("Normal Atlas", 2D) = "bump" {}
- _Impostors_Metallic_Gloss_Atlas("Metallic Gloss Atlas", 2D) = "white" {}
- _Impostors_Depth_Atlas("Depth Atlas", 2D) = "white" {}
+ _Impostors_Metallic_Gloss_Depth_Atlas("Metallic Gloss Depth Atlas", 2D) = "white" {}
_Impostors_Grid_Resolution("Grid Resolution", Int) = 5
_Impostors_Sphere_Radius("Sphere Radius", Float) = 1.0
_Impostors_Near_Clip("Near clip distance", Float) = 0.01
diff --git a/Scripts/Impostors.cs b/Scripts/Impostors.cs
index 3212341..29d92d0 100755
--- a/Scripts/Impostors.cs
+++ b/Scripts/Impostors.cs
@@ -444,21 +444,42 @@ public class Impostors : MonoBehaviour
string baseName = gameObject.name.Replace(" ", "_");
+ // Dilate before combining
+ DilateTexture(albedoAtlas, albedoAtlas, preserveAlpha: true);
+ DilateTexture(normalAtlas, albedoAtlas);
+ DilateTexture(metallicGlossAtlas, albedoAtlas);
+ DilateDepthTexture(depthAtlas, albedoAtlas);
+
+ // Combine metallic_gloss (RG) with depth (B) into a single texture
+ Texture2D combinedAtlas = new Texture2D(metallicGlossAtlas.width, metallicGlossAtlas.height, TextureFormat.RGBA32, false);
+ Color[] metallicGlossPixels = metallicGlossAtlas.GetPixels();
+ Color[] depthPixels = depthAtlas.GetPixels();
+ Color[] combinedPixels = new Color[metallicGlossPixels.Length];
+
+ for (int i = 0; i < combinedPixels.Length; i++)
+ {
+ combinedPixels[i] = new Color(
+ metallicGlossPixels[i].r, // Metallic
+ metallicGlossPixels[i].g, // Gloss
+ depthPixels[i].r, // Depth
+ 1.0f // Alpha (unused)
+ );
+ }
+ combinedAtlas.SetPixels(combinedPixels);
+ combinedAtlas.Apply();
+
+ // Clean up the separate textures
+ DestroyImmediate(metallicGlossAtlas);
+ DestroyImmediate(depthAtlas);
+
var exportSettings = new (TextureExportSettings settings, string materialProp)[]
{
(new TextureExportSettings("albedo", mipmaps: true, sRGB: true, alphaTransparency: true), "_Impostors_Atlas"),
(new TextureExportSettings("normal", mipmaps: true, sRGB: false), "_Impostors_Normal_Atlas"),
- (new TextureExportSettings("metallic_gloss", mipmaps: true, sRGB: false), "_Impostors_Metallic_Gloss_Atlas"),
- (new TextureExportSettings("depth", isEXR: false, mipmaps: false, sRGB: false, filter: FilterMode.Bilinear, uncompressed: true), "_Impostors_Depth_Atlas")
+ (new TextureExportSettings("metallic_gloss_depth", mipmaps: true, sRGB: false, uncompressed: true), "_Impostors_Metallic_Gloss_Depth_Atlas")
};
- // Dilate RGB to prevent dark halos from texture filtering
- DilateTexture(albedoAtlas, albedoAtlas, preserveAlpha: true);
- DilateTexture(normalAtlas, albedoAtlas);
- DilateTexture(metallicGlossAtlas, albedoAtlas);
- DilateDepthTexture(depthAtlas, albedoAtlas);
-
- Texture2D[] atlases = { albedoAtlas, normalAtlas, metallicGlossAtlas, depthAtlas };
+ Texture2D[] atlases = { albedoAtlas, normalAtlas, combinedAtlas };
string[] paths = new string[exportSettings.Length];
for (int i = 0; i < exportSettings.Length; i++)
SaveAndConfigureTexture(atlases[i], exportSettings[i].settings, baseName, out paths[i]);
diff --git a/globals.cginc b/globals.cginc
index c50e7fc..0341146 100755
--- a/globals.cginc
+++ b/globals.cginc
@@ -185,8 +185,8 @@ float _Parallax_Heightmap_Ray_Marching_Steps;
Texture2D _Impostors_Atlas;
float4 _Impostors_Atlas_TexelSize;
Texture2D _Impostors_Normal_Atlas;
-Texture2D _Impostors_Metallic_Gloss_Atlas;
-Texture2D _Impostors_Depth_Atlas;
+// R=metallic, G=gloss, B=depth
+Texture2D _Impostors_Metallic_Gloss_Depth_Atlas;
int _Impostors_Grid_Resolution;
float _Impostors_Sphere_Radius;
float _Impostors_Near_Clip;
diff --git a/impostor.cginc b/impostor.cginc
index 048eaf6..1afbdea 100755
--- a/impostor.cginc
+++ b/impostor.cginc
@@ -108,7 +108,7 @@ AtlasUvGrad PrepareAtlasUvGrad(float2 cell, float2 uvInCell, float invGridRes) {
float SampleImpostorDepthCell(float2 cell, float2 uvInCell, float invGridRes) {
AtlasUvGrad uv = PrepareAtlasUvGrad(cell, uvInCell, invGridRes);
- return _Impostors_Depth_Atlas.SampleGrad(bilinear_clamp_s, uv.atlasUv, uv.gradX, uv.gradY).r;
+ return _Impostors_Metallic_Gloss_Depth_Atlas.SampleGrad(bilinear_clamp_s, uv.atlasUv, uv.gradX, uv.gradY).b;
}
float SampleImpostorAlphaCell(float2 cell, float2 uvInCell, float invGridRes) {
@@ -121,7 +121,8 @@ ImpostorSample SampleImpostorCell(float2 cell, float2 uvInCell, float invGridRes
ImpostorSample s;
s.albedo = _Impostors_Atlas.SampleGrad(bilinear_clamp_s, uv.atlasUv, uv.gradX, uv.gradY);
s.normal = _Impostors_Normal_Atlas.SampleGrad(bilinear_clamp_s, uv.atlasUv, uv.gradX, uv.gradY);
- s.metallicGloss = _Impostors_Metallic_Gloss_Atlas.SampleGrad(bilinear_clamp_s, uv.atlasUv, uv.gradX, uv.gradY);
+ float4 mgd = _Impostors_Metallic_Gloss_Depth_Atlas.SampleGrad(bilinear_clamp_s, uv.atlasUv, uv.gradX, uv.gradY);
+ s.metallicGloss = float4(mgd.rg, 0, 0);
return s;
}
@@ -331,7 +332,7 @@ ImpostorResult impostor_frag(float3 worldPos) {
float3 normalOS = blended.normal.xyz * 2.0 - 1.0;
result.normal = normalize(mul((float3x3)unity_ObjectToWorld, normalOS));
result.metallic = blended.metallicGloss.r;
- result.smoothness = blended.metallicGloss.a;
+ result.smoothness = blended.metallicGloss.g;
#if defined(_IMPOSTORS_DEPTH)
// Reuse depth samples for position reconstruction