ShadeColor

This commit is contained in:
ousttrue
2025-02-07 14:18:23 +09:00
parent 7e22c51c1b
commit 77b285fc76
5 changed files with 1824 additions and 303 deletions

View File

@@ -118,7 +118,7 @@ namespace UniVRM10
}
}
private static bool TryGetShadeMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
public static bool TryGetShadeMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
{
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out key, out desc);
}

View File

@@ -2554,10 +2554,10 @@
"m_Expanded": false,
"m_Position": {
"serializedVersion": "2",
"x": -14.666682243347168,
"y": 77.33332824707031,
"width": 157.33334350585938,
"height": 158.66665649414063
"x": -60.00007629394531,
"y": 77.33324432373047,
"width": 157.3333282470703,
"height": 157.33343505859376
}
},
"m_Slots": [
@@ -3029,10 +3029,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 536.0,
"y": -22.00001335144043,
"width": 149.33331298828126,
"height": 198.66668701171876
"x": 660.666748046875,
"y": 2.000000238418579,
"width": 149.3331298828125,
"height": 222.66671752929688
}
},
"m_Slots": [
@@ -3244,10 +3244,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 231.33331298828126,
"y": 17.333377838134767,
"width": 127.33328247070313,
"height": 119.99998474121094
"x": 125.33326721191406,
"y": -38.66671371459961,
"width": 209.33335876464845,
"height": 303.9999694824219
}
},
"m_Slots": [
@@ -3267,7 +3267,7 @@
"x"
],
"m_Precision": 0,
"m_PreviewExpanded": false,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
@@ -3741,10 +3741,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 227.33331298828126,
"y": -282.0,
"width": 131.33334350585938,
"height": 119.99998474121094
"x": 253.9999237060547,
"y": -385.9999694824219,
"width": 209.33335876464845,
"height": 303.9999694824219
}
},
"m_Slots": [
@@ -3764,7 +3764,7 @@
"x"
],
"m_Precision": 0,
"m_PreviewExpanded": false,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {

View File

@@ -1,3 +1,4 @@
using System.Dynamic;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
@@ -17,21 +18,11 @@ namespace UniVRM10.VRM10Viewer
/// When using shadergraph, require "Set as Main Texture"
/// </summary>
private static readonly int BaseMapProp = Shader.PropertyToID("_BaseMap");
/// <summary>
/// float = 1.0
/// </summary>
private static readonly int OcclusionStrengthProp = Shader.PropertyToID("_OcclusionStrength");
/// <summary>
/// Texture2D.Red = 1.0.
/// </summary>
private static readonly int OcclusionMapProp = Shader.PropertyToID("_OcclusionMap");
private static readonly int RoughnessProp = Shader.PropertyToID("_Roughness");
private static readonly int MetallicProp = Shader.PropertyToID("_Metallic");
/// <summary>
/// Texture2D.Green = 1.0. The roughness
/// Texture2D.Blue = 1.0. The metalness
/// </summary>
private static readonly int MetallicRoughnessMapProp = Shader.PropertyToID("_MetallicRoughnessMap");
private static readonly int ShadingColorFactorProp = Shader.PropertyToID("_ShadingColor");
private static readonly int ShadingMapProp = Shader.PropertyToID("_ShadingMap");
private static readonly int ShadingToonyFactorProp = Shader.PropertyToID("_ShadingToonyFactor");
/// <summary>
/// float = 1.0
/// </summary>
@@ -40,6 +31,7 @@ namespace UniVRM10.VRM10Viewer
/// Texture2D = [0, 0, 1.0]
/// </summary>
private static readonly int BumpMapProp = Shader.PropertyToID("_BumpMap");
/// <summary>
/// Color = black
/// </summary>
@@ -48,6 +40,7 @@ namespace UniVRM10.VRM10Viewer
/// Texture2D = black
/// </summary>
private static readonly int EmissionMapProp = Shader.PropertyToID("_EmissionMap");
/// <summary>
/// boolean keyword
/// </summary>
@@ -84,34 +77,20 @@ namespace UniVRM10.VRM10Viewer
set => Material.SetTextureScale(BaseMapProp, value);
}
public float OcclusionStrength
public Color ShadingColorFactorSrgb
{
get => Material.GetFloat(OcclusionStrengthProp);
set => Material.SetFloat(OcclusionStrengthProp, value);
get => Material.GetColor(ShadingColorFactorProp);
set => Material.SetColor(ShadingColorFactorProp, value);
}
public Texture OcclusionTexture
public Texture ShadingTexture
{
get => Material.GetTexture(OcclusionMapProp);
set
{
Material.SetTexture(OcclusionMapProp, value);
}
get => Material.GetTexture(ShadingMapProp);
set => Material.SetTexture(ShadingMapProp, value);
}
public float Roughness
public float ShadingToonyFactor
{
get => Material.GetFloat(RoughnessProp);
set => Material.SetFloat(RoughnessProp, value);
}
public float Metallic
{
get => Material.GetFloat(MetallicProp);
set => Material.SetFloat(MetallicProp, value);
}
public Texture MetallicRoughnessMap
{
get => Material.GetTexture(MetallicRoughnessMapProp);
set => Material.SetTexture(MetallicRoughnessMapProp, value);
get => Material.GetFloat(ShadingToonyFactorProp);
set => Material.SetFloat(ShadingToonyFactorProp, value);
}
public float BumpScale

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UniGLTF;
using UniGLTF.Extensions.VRMC_materials_mtoon;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
@@ -43,15 +44,15 @@ namespace UniVRM10.VRM10Viewer
);
return true;
Task AsyncAction(Material x, GetTextureAsyncFunc y, IAwaitCaller z) => GenerateMaterialAsync(data, src, x, y, z);
Task AsyncAction(Material x, GetTextureAsyncFunc y, IAwaitCaller z) => GenerateMaterialAsync(data, src, mtoon, x, y, z);
}
public static async Task GenerateMaterialAsync(GltfData data, glTFMaterial src, Material dst, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
public static async Task GenerateMaterialAsync(GltfData data, glTFMaterial src, VRMC_materials_mtoon mtoon, Material dst, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var context = new TinyMToonMaterialContext(dst);
// ImportSurfaceSettings(src, context);
await ImportBaseColorAsync(data, src, context, getTextureAsync, awaitCaller);
await ImportBaseShadeColorAsync(data, src, mtoon, context, getTextureAsync, awaitCaller);
// await ImportMetallicRoughnessAsync(data, src, context, getTextureAsync, awaitCaller);
// await ImportOcclusionAsync(data, src, context, getTextureAsync, awaitCaller);
// await ImportNormalAsync(data, src, context, getTextureAsync, awaitCaller);
@@ -60,7 +61,7 @@ namespace UniVRM10.VRM10Viewer
// context.Validate();
}
public static async Task ImportBaseColorAsync(GltfData data, glTFMaterial src, TinyMToonMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
public static async Task ImportBaseShadeColorAsync(GltfData data, glTFMaterial src, VRMC_materials_mtoon mtoon, TinyMToonMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var baseColorFactor = GltfMaterialImportUtils.ImportLinearBaseColorFactor(data, src);
if (baseColorFactor.HasValue)
@@ -77,6 +78,17 @@ namespace UniVRM10.VRM10Viewer
context.BaseTextureScale = desc.Scale;
}
}
context.ShadingToonyFactor = mtoon.ShadingToonyFactor.GetValueOrDefault();
var shadeColor = mtoon.ShadeColorFactor?.ToColor3(UniGLTF.ColorSpace.Linear, UniGLTF.ColorSpace.sRGB);
context.ShadingColorFactorSrgb = shadeColor.GetValueOrDefault(Color.white);
if (mtoon is { ShadeMultiplyTexture: { Index: >= 0 } })
{
if (Vrm10MToonTextureImporter.TryGetShadeMultiplyTexture(data, mtoon, out var _, out var desc))
{
context.ShadingTexture = await getTextureAsync(desc, awaitCaller);
}
}
}
}
}