Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Runtime/Scripts/BaseMeshSync.Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ private bool SetSerializedTextureForMaterial(Material mat, int textureNameID) {
textureNameID == MeshSyncConstants._MaskMap) {
mat.EnableKeyword(MeshSyncConstants._METALLICGLOSSMAP);
mat.EnableKeyword(MeshSyncConstants._METALLICSPECGLOSSMAP);
}

TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(savePath);
if (importer != null) {
importer.sRGBTexture = false;
importer.alphaIsTransparency = false;
importer.ignorePngGamma = true;
importer.SaveAndReimport();
AssetDatabase.Refresh();
}
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(savePath);
if (importer != null) {
importer.sRGBTexture = false;
importer.alphaIsTransparency = false;
importer.ignorePngGamma = true;
importer.SaveAndReimport();
AssetDatabase.Refresh();
}

return true;
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Scripts/Extensions/MaterialExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public static void SetTextureAndReleaseExistingRenderTextures(this Material mat,
existingRenderTexture.Release();

mat.SetTexture(nameID, texture);

// Ensure main texture is set if the name is not _MainTex!
if (nameID == MeshSyncConstants._MainTex) {
mat.mainTexture = texture;
}
}
}
}
4 changes: 3 additions & 1 deletion Runtime/Shaders/ComputeShaderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

namespace Unity.MeshSync {
internal class ComputeShaderHelper {
Expand Down Expand Up @@ -29,7 +30,8 @@ public RenderTexture RenderToTexture(Texture existingTexture) {
renderTarget.height != maxTextureSize.y) {
if (renderTarget != null) renderTarget.Release();

renderTarget = new RenderTexture(maxTextureSize.x, maxTextureSize.y, 32) {
// We don't want sRGB here!
renderTarget = new RenderTexture(maxTextureSize.x, maxTextureSize.y, 32, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so you need 16 bit per channel instead of 8 bit as well here.
(Just a comment)

enableRandomWrite = true
};

Expand Down
28 changes: 23 additions & 5 deletions Runtime/Shaders/MapsBaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,31 @@ private static bool FindTexture(int nameID,

// If there is no such texture, create one with the given fallback value:

float value = fallbackPropertyValue;
if (materialProperties.TryGetValue(fallbackPropertyNameID, out IMaterialPropertyData fallbackMaterialProperty))
value = fallbackMaterialProperty.floatValue;
Color value = new Color(
fallbackPropertyValue,
fallbackPropertyValue,
fallbackPropertyValue,
fallbackPropertyValue);

if (materialProperties.TryGetValue(fallbackPropertyNameID,
out IMaterialPropertyData fallbackMaterialProperty)) {
switch (fallbackMaterialProperty.type) {
case IMaterialPropertyData.Type.Float:
float v = fallbackMaterialProperty.floatValue;
value = new Color(v, v, v, v);
break;
case IMaterialPropertyData.Type.Vector:
value = fallbackMaterialProperty.vectorValue;
break;
default:
Debug.LogError($"Unsupported fallback property type: {fallbackMaterialProperty.type}!");
break;
}
}

const int dim = 8;

Color[] pixels = Enumerable.Repeat(new Color(value, value, value, value), dim * dim).ToArray();
Color[] pixels = Enumerable.Repeat(value, dim * dim).ToArray();

disposableTexture =
new Texture2DDisposable(new Texture2D(dim, dim, UnityEngine.TextureFormat.RFloat, false, true));
Expand Down Expand Up @@ -176,7 +194,7 @@ private static void BakeSmoothness(Material destMat,
// Bake to albedo alpha
channelName = MeshSyncConstants._MainTex;
texturesExist |=
FindTexture(MeshSyncConstants._MainTex, textureHolders, materialProperties, 0, 0,
FindTexture(MeshSyncConstants._MainTex, textureHolders, materialProperties, MeshSyncConstants._Color, 0,
out rgbTexture);
}
else {
Expand Down