Skip to content

Commit

Permalink
TintColorMapのOffsetにCustomCoord追加
Browse files Browse the repository at this point in the history
  • Loading branch information
S20817 committed May 20, 2024
1 parent 6f590bb commit 0632fd6
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 67 deletions.
8 changes: 5 additions & 3 deletions Assets/Nova/Editor/Core/Scripts/MaterialPropertyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public static class MaterialPropertyNames
public const string TintMap3DProgress = "_TintMap3DProgress";
public const string TintMap3DProgressCoord = "_TintMap3DProgressCoord";
public const string TintMapSliceCount = "_TintMapSliceCount";
public const string TintMapOffsetXCoord = "_TintMapOffsetXCoord";
public const string TintMapOffsetYCoord = "_TintMapOffsetYCoord";
public const string TintMapBlendRate = "_TintBlendRate";
public const string TintMapBlendRateCoord = "_TintBlendRateCoord";
public const string TintRimProgress = "_TintRimProgress";
Expand All @@ -87,7 +89,7 @@ public static class MaterialPropertyNames
public const string FlowIntensity = "_FlowIntensity";
public const string FlowIntensityCoord = "_FlowIntensityCoord";
public const string FlowMapTarget = "_FlowMapTarget";

// Parallax Map
public const string ParallaxMapMode = "_ParallaxMapMode";
public const string ParallaxMap = "_ParallaxMap";
Expand Down Expand Up @@ -164,15 +166,15 @@ public static class MaterialPropertyNames
// Distortion
public const string DistortionIntensity = "_DistortionIntensity";
public const string DistortionIntensityCoord = "_DistortionIntensityCoord";

// Vertex Deformation
public const string VertexDeformationMap = "_VertexDeformationMap";
public const string VertexDeformationMapOffsetXCoord = "_VertexDeformationMapOffsetXCoord";
public const string VertexDeformationMapOffsetYCoord = "_VertexDeformationMapOffsetYCoord";
public const string VertexDeformationMapChannel = "_VertexDeformationMapChannel";
public const string VertexDeformationIntensity = "_VertexDeformationIntensity";
public const string VertexDeformationIntensityCoord = "_VertexDeformationIntensityCoord";

// Shadow Caster
public const string ShadowCasterEnabled = "_ShadowCasterEnabled";
public const string ShadowCasterApplyVertexDeformation = "_ShadowCasterApplyVertexDeformation";
Expand Down
22 changes: 13 additions & 9 deletions Assets/Nova/Editor/Core/Scripts/ParticlesUberCommonGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,17 @@ private void InternalDrawTintColorProperties()
}
else if (tintColorMode == TintColorMode.Texture2D)
{
MaterialEditorUtility.DrawTexture(_editor, props.TintMapProp.Value, true);
MaterialEditorUtility.DrawTexture(_editor, props.TintMapProp.Value,
props.TintMapOffsetXCoordProp.Value, props.TintMapOffsetYCoordProp.Value,
null, null);
}
else if (tintColorMode == TintColorMode.Texture3D)
{
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
MaterialEditorUtility.DrawTexture(_editor, props.TintMap3DProp.Value, true);
MaterialEditorUtility.DrawTexture(_editor, props.TintMap3DProp.Value,
props.TintMapOffsetXCoordProp.Value, props.TintMapOffsetYCoordProp.Value,
null, null);

if (changeCheckScope.changed && props.TintMap3DProp.Value.textureValue != null)
{
Expand Down Expand Up @@ -587,24 +591,24 @@ private void InternalDrawVertexDeformationMapProperties()
props.VertexDeformationIntensityProp.Value,
props.VertexDeformationIntensityCoordProp.Value);
}

private void InternalDrawShadowCasterProperties()
{
var props = _commonMaterialProperties;
MaterialEditorUtility.DrawToggleProperty(_editor, "Enable", props.ShadowCasterEnabledProp.Value);
if (props.ShadowCasterEnabledProp.Value.floatValue < 0.5f)
if (props.ShadowCasterEnabledProp.Value.floatValue < 0.5f)
return;

MaterialEditorUtility.DrawToggleProperty(_editor, "Apply Vertex Deformation", props.ShadowCasterApplyVertexDeformationProp.Value);

MaterialEditorUtility.DrawToggleProperty(_editor, "Alpha Test Enable", props.ShadowCasterAlphaTestEnabledProp.Value);
if (props.ShadowCasterAlphaTestEnabledProp.Value.floatValue < 0.5f)
return;

EditorGUI.indentLevel++;
MaterialEditorUtility.DrawFloatRangeProperty(_editor, "Cutoff", props.ShadowCasterAlphaCutoffProp.Value, 0, 1);
EditorGUI.indentLevel--;

EditorGUI.LabelField(EditorGUILayout.GetControlRect(), "Alpha Affected By");
EditorGUI.indentLevel++;
MaterialEditorUtility.DrawToggleProperty(_editor, "Tint Color", props.ShadowCasterAlphaAffectedByTintColorProp.Value);
Expand Down Expand Up @@ -632,4 +636,4 @@ private void InternalDrawShadowCasterProperties()

# endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public void Setup(MaterialProperty[] properties)
TintMap3DProgressProp.Setup(properties);
TintMap3DProgressCoordProp.Setup(properties);
TintMapSliceCountProp.Setup(properties);
TintMapOffsetXCoordProp.Setup(properties);
TintMapOffsetYCoordProp.Setup(properties);
TintMapBlendRateProp.Setup(properties);
TintMapBlendRateCoordProp.Setup(properties);
TintRimProgressProp.Setup(properties);
Expand Down Expand Up @@ -177,7 +179,7 @@ public void Setup(MaterialProperty[] properties)
VertexDeformationMapChannelProp.Setup(properties);
VertexDeformationIntensityProp.Setup(properties);
VertexDeformationIntensityCoordProp.Setup(properties);

// Shadow Caster
ShadowCasterEnabledProp.Setup(properties);
ShadowCasterApplyVertexDeformationProp.Setup(properties);
Expand Down Expand Up @@ -273,6 +275,10 @@ public void Setup(MaterialProperty[] properties)

public ParticlesGUI.Property TintMapSliceCountProp { get; } = new(PropertyNames.TintMapSliceCount);

public ParticlesGUI.Property TintMapOffsetXCoordProp { get; } = new(PropertyNames.TintMapOffsetXCoord);

public ParticlesGUI.Property TintMapOffsetYCoordProp { get; } = new(PropertyNames.TintMapOffsetYCoord);

public ParticlesGUI.Property TintMapBlendRateProp { get; } = new(PropertyNames.TintMapBlendRate);

public ParticlesGUI.Property TintMapBlendRateCoordProp { get; } = new(PropertyNames.TintMapBlendRateCoord);
Expand Down Expand Up @@ -488,7 +494,7 @@ public ParticlesGUI.Property
#endregion

#region Shadow Caster Material Properties

public ParticlesGUI.Property ShadowCasterEnabledProp { get; } = new(PropertyNames.ShadowCasterEnabled);
public ParticlesGUI.Property ShadowCasterApplyVertexDeformationProp { get; } = new(PropertyNames.ShadowCasterApplyVertexDeformation);
public ParticlesGUI.Property ShadowCasterAlphaTestEnabledProp { get; } = new(PropertyNames.ShadowCasterAlphaTestEnabled);
Expand All @@ -497,7 +503,7 @@ public ParticlesGUI.Property
public ParticlesGUI.Property ShadowCasterAlphaAffectedByFlowMapProp { get; } = new(PropertyNames.ShadowCasterAlphaAffectedByFlowMap);
public ParticlesGUI.Property ShadowCasterAlphaAffectedByAlphaTransitionMapProp { get; } = new(PropertyNames.ShadowCasterAlphaAffectedByAlphaTransitionMap);
public ParticlesGUI.Property ShadowCasterAlphaAffectedByTransparencyLuminanceProp { get; } = new(PropertyNames.ShadowCasterAlphaAffectedByTransparencyLuminance);

#endregion
}
}
}
14 changes: 10 additions & 4 deletions Assets/Nova/Editor/Core/Scripts/RendererErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static bool CheckErrorWithMaterial(Material material)

return CheckError(renderersWithMaterial, correctVertexStreams, correctVertexStreamsInstanced);
}

/// <summary>
/// Corrects errors in renderers using the specified material.
/// </summary>
Expand Down Expand Up @@ -106,8 +106,14 @@ private static bool IsCustomCoordUsedInTintColor(ParticlesUberCommonMaterialProp
|| IsCustomCoordUsed(commonMaterialProperties.TintRimSharpnessCoordProp);

var tintMapMode = (TintColorMode)commonMaterialProperties.TintColorModeProp.Value.floatValue;
if (tintMapMode == TintColorMode.Texture3D)
isCustomCoordUsed |= IsCustomCoordUsed(commonMaterialProperties.TintMap3DProgressCoordProp);
if (tintMapMode == TintColorMode.Texture2D || tintMapMode == TintColorMode.Texture3D)
{
isCustomCoordUsed |= IsCustomCoordUsed(commonMaterialProperties.TintMapOffsetXCoordProp)
|| IsCustomCoordUsed(commonMaterialProperties.TintMapOffsetYCoordProp);

if (tintMapMode == TintColorMode.Texture3D)
isCustomCoordUsed |= IsCustomCoordUsed(commonMaterialProperties.TintMap3DProgressCoordProp);
}
}

return isCustomCoordUsed;
Expand Down Expand Up @@ -302,4 +308,4 @@ internal static List<ParticleSystemRenderer> FindRendererWithMaterial(Material m
: correctVertexStreams);
}
}
}
}
6 changes: 4 additions & 2 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUber.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ float4 _TintMap3D_ST;
float _TintMap3DProgress;
DECLARE_CUSTOM_COORD(_TintMap3DProgressCoord);
float _TintMapSliceCount;
DECLARE_CUSTOM_COORD(_TintMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_TintMapOffsetYCoord);
float _TintBlendRate;
float _TintBlendRateCoord;
float _TintRimProgress;
Expand Down Expand Up @@ -490,7 +492,7 @@ inline void ApplyEmissionColor(in out half4 color, half2 emissionMapUv, float in
{
// Texture compression may introduce an error of 1/256, so it's advisable to allow for some margin
const half tex_comp_err_margin = 0.004;

half emissionIntensity = 0;
half emissionColorRampU = 0;
#ifdef _EMISSION_AREA_ALL
Expand Down Expand Up @@ -625,7 +627,7 @@ inline half2 GetParallaxMappingUVOffset(in half2 uv, in half progress, in half c
{
half4 map = SAMPLE_PARALLAX_MAP(uv, progress);
half height = map[(int)channel];
half2 offset = ParallaxOffset(height, scale, viewDirTS);
half2 offset = ParallaxOffset(height, scale, viewDirTS);
return offset;
}
#endif
46 changes: 24 additions & 22 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUberDepthNormalsCore.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define NOVA_PARTICLESUBERDEPTHNORMALSCORE_INCLUDED


// If defined _ALPHATEST_ENABLED or _NORMAL_MAP_ENABLED, base map uv is enabled.
#if defined( _ALPHATEST_ENABLED ) || defined(_NORMAL_MAP_ENABLED)
// If defined _ALPHATEST_ENABLED or _NORMAL_MAP_ENABLED, base map uv is enabled.
#if defined( _ALPHATEST_ENABLED ) || defined(_NORMAL_MAP_ENABLED)
#define _USE_BASE_MAP_UV
#endif

Expand All @@ -29,7 +29,7 @@
#endif
#endif

#if defined( _ALPHATEST_ENABLED ) || defined(_USE_FLOW_MAP) || defined(_USE_BASE_MAP_UV)
#if defined( _ALPHATEST_ENABLED ) || defined(_USE_FLOW_MAP) || defined(_USE_BASE_MAP_UV)
#define _USE_CUSTOM_COORD
#endif

Expand Down Expand Up @@ -60,7 +60,7 @@ struct AttributesDrawDepth
#endif
#ifdef _ALPHATEST_ENABLED // This attributes is not used for opaque objects.
float4 color : COLOR;

#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Expand All @@ -79,7 +79,7 @@ struct VaryingsDrawDepth
float3 binormalWS : BINORMAL;
#endif
#endif

#ifdef _USE_CUSTOM_COORD
INPUT_CUSTOM_COORD(0, 1)
#endif
Expand All @@ -90,7 +90,7 @@ struct VaryingsDrawDepth
#if defined( _USE_FLOW_MAP ) || defined(_USE_TRANSITION_MAP)
float4 flowTransitionUVs : TEXCOORD3; // xy: FlowMap UV, zw: TransitionMap UV
#endif

#ifdef _ALPHATEST_ENABLED // This attributes is not used for opaque objects.
float4 color : COLOR;
float4 tintEmissionUV : TEXCOORD4; // xy: TintMap UV, zw: EmissionMap UV
Expand All @@ -99,7 +99,7 @@ struct VaryingsDrawDepth
#ifdef FRAGMENT_USE_VIEW_DIR_WS
float3 viewDirWS : TEXCOORD6;
#endif

#ifdef USE_PROJECTED_POSITION
float4 projectedPosition : TEXCOORD7;
#endif
Expand All @@ -110,7 +110,7 @@ struct VaryingsDrawDepth
/**
* \brief Initialize output data from vertex shader for DepthOnly and DepthNormals pass.
* \param[in] input Input attributes to vertex shader.
* \param[in,out] output Output data from vertex shader.
* \param[in,out] output Output data from vertex shader.
*/
inline void InitializeVertexOutputDrawDepth(in AttributesDrawDepth input, in out VaryingsDrawDepth output)
{
Expand All @@ -129,7 +129,7 @@ inline void InitializeVertexOutputDrawDepth(in AttributesDrawDepth input, in out
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
output.viewDirWS = GetWorldSpaceViewDir(positionWS);
#endif

#ifdef USE_PROJECTED_POSITION
output.projectedPosition = ComputeScreenPos(output.positionHCS);
#endif
Expand All @@ -147,7 +147,7 @@ inline void InitializeFragmentInputDrawDepth(in out VaryingsDrawDepth input)
#endif

#ifdef _ALPHATEST_ENABLED // This code is not used for opaque objects.
#ifdef FRAGMENT_USE_VIEW_DIR_WS
#ifdef FRAGMENT_USE_VIEW_DIR_WS
input.viewDirWS = normalize(input.viewDirWS);
#endif
#endif
Expand All @@ -156,7 +156,7 @@ inline void InitializeFragmentInputDrawDepth(in out VaryingsDrawDepth input)
/**
* \brief Vertex shader entry point.
* \param input Input attribute.
* \return Return data of VaryingsDrawDepth Structure.
* \return Return data of VaryingsDrawDepth Structure.
*/
VaryingsDrawDepth vert(AttributesDrawDepth input)
{
Expand All @@ -169,7 +169,7 @@ VaryingsDrawDepth vert(AttributesDrawDepth input)
TRANSFER_CUSTOM_COORD(input, output);
#endif
InitializeVertexOutputDrawDepth(input, output);

#ifdef _USE_BASE_MAP_UV
// Base Map UV
float2 baseMapUv = input.texcoord.xy;
Expand Down Expand Up @@ -197,7 +197,7 @@ VaryingsDrawDepth vert(AttributesDrawDepth input)
output.flowTransitionUVs.w += GET_CUSTOM_COORD(_AlphaTransitionMapOffsetYCoord)
#endif
#ifdef _ALPHATEST_ENABLED // This code is not used for opaque objects.

// Base Map Progress
#ifdef _BASE_MAP_MODE_2D_ARRAY
float baseMapProgress = _BaseMapProgress + GET_CUSTOM_COORD(_BaseMapProgressCoord);
Expand All @@ -210,6 +210,8 @@ VaryingsDrawDepth vert(AttributesDrawDepth input)
// Tint Map UV
#if defined(_TINT_MAP_ENABLED) || defined(_TINT_MAP_3D_ENABLED)
output.tintEmissionUV.xy = TRANSFORM_TINT_MAP(input.texcoord.xy);
output.tintEmissionUV.x += GET_CUSTOM_COORD(_TintMapOffsetXCoord);
output.tintEmissionUV.y += GET_CUSTOM_COORD(_TintMapOffsetYCoord);
#endif

// Tint Map Progress
Expand Down Expand Up @@ -247,7 +249,7 @@ VaryingsDrawDepth vert(AttributesDrawDepth input)
//Fog
// output.transitionEmissionProgresses.z = ComputeFogFactor(output.positionHCS.z);
#endif

return output;
}

Expand All @@ -261,18 +263,18 @@ half4 frag(VaryingsDrawDepth input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
SETUP_FRAGMENT;

#ifdef _USE_CUSTOM_COORD
SETUP_CUSTOM_COORD(input);
#endif

InitializeFragmentInputDrawDepth(input);

#if defined(_TRANSPARENCY_BY_RIM) || defined(_TINT_AREA_RIM)
half rim = 1.0 - abs(dot(input.normalWS, input.viewDirWS));
#endif
// Flow map

// Flow map
#if defined( _USE_FLOW_MAP)
half intensity = _FlowIntensity + GET_CUSTOM_COORD(_FlowIntensityCoord);
half2 flowMapUvOffset = GetFlowMapUvOffset(_FlowMap, sampler_FlowMap, intensity, input.flowTransitionUVs.xy, _FlowMapChannelsX, _FlowMapChannelsY);
Expand All @@ -289,11 +291,11 @@ half4 frag(VaryingsDrawDepth input) : SV_Target
input.flowTransitionUVs.zw += flowMapUvOffset;
#endif
#endif

#ifdef _ALPHATEST_ENABLED // This code is not used for opaque objects.
// Base Color
half4 color = SAMPLE_BASE_MAP(input.baseMapUVAndProgresses.xy, input.baseMapUVAndProgresses.z);

// Tint Color
#if defined(_TINT_AREA_ALL) || defined(_TINT_AREA_RIM)
half tintBlendRate = _TintBlendRate + GET_CUSTOM_COORD(_TintBlendRateCoord);
Expand All @@ -312,7 +314,7 @@ half4 frag(VaryingsDrawDepth input) : SV_Target
ModulateAlphaTransitionProgress(alphaTransitionProgress, input.color.a);
color.a *= GetTransitionAlpha(alphaTransitionProgress, input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, _AlphaTransitionMapChannelsX);
#endif

// NOTE : Not need in DepthNormals pass.
// Color Correction
// ApplyColorCorrection(color.rgb);
Expand Down Expand Up @@ -354,7 +356,7 @@ half4 frag(VaryingsDrawDepth input) : SV_Target
#endif

AlphaClip(color.a, _Cutoff);

// NOTE : Not need in DepthNormals pass.
// color.rgb = ApplyAlpha(color.rgb, color.a);
#endif
Expand Down
Loading

0 comments on commit 0632fd6

Please sign in to comment.