Skip to content

Commit

Permalink
Merge pull request #95 from CyberAgentGameEntertainment/feature/disto…
Browse files Browse the repository at this point in the history
…rtion_add_normal_option

Add Unpack Normal Option To Distortion
  • Loading branch information
CA-Tatami authored Dec 25, 2024
2 parents d2fdd7d + 7aa37fa commit c62a857
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 51 deletions.
1 change: 1 addition & 0 deletions Assets/Nova/Editor/Core/Scripts/MaterialPropertyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static class MaterialPropertyNames
public const string BaseMapRotationCoord = "_BaseMapRotationCoord";
public const string BaseMapRotationOffsets = "_BaseMapRotationOffsets";
public const string BaseMapMirrorSampling = "_BaseMapMirrorSampling";
public const string BaseMapUnpackNormal = "_BaseMapUnpackNormal";

// Tint Color
public const string TintAreaMode = "_TintAreaMode";
Expand Down
90 changes: 46 additions & 44 deletions Assets/Nova/Editor/Core/Scripts/ParticlesDistortionGUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------
// Copyright 2022 CyberAgent, Inc.
// Copyright 2024 CyberAgent, Inc.
// --------------------------------------------------------------

using Nova.Editor.Foundation.Scripts;
Expand All @@ -14,13 +14,6 @@ namespace Nova.Editor.Core.Scripts
/// </summary>
internal sealed class ParticlesDistortionGUI : ParticlesGUI
{
#region Render Settings Material Properties

private readonly Property _cullProp = new Property(PropertyNames.Cull);
private readonly Property _zTestProp = new Property(PropertyNames.ZTest);

#endregion

protected override void SetupProperties(MaterialProperty[] properties)
{
// Render Settings
Expand All @@ -37,6 +30,7 @@ protected override void SetupProperties(MaterialProperty[] properties)
_baseMapRotationCoordProp.Setup(properties);
_baseMapRotationOffsetsProp.Setup(properties);
_baseMapMirrorSamplingProp.Setup(properties);
_baseMapUnpackNormalProp.Setup(properties);
_distortionIntensityProp.Setup(properties);
_distortionIntensityCoordProp.Setup(properties);

Expand Down Expand Up @@ -104,7 +98,8 @@ protected override void DrawGUI(MaterialEditor editor, MaterialProperty[] proper
DistortionFoldout.Value = foldoutScope.Foldout;
}

using (var foldoutScope = new MaterialEditorUtility.FoldoutHeaderScope(FlowMapFoldout.Value, "Flow Map"))
using (var foldoutScope =
new MaterialEditorUtility.FoldoutHeaderScope(FlowMapFoldout.Value, "Flow Mapping"))
{
if (foldoutScope.Foldout) DrawFlowMapProperties(editor, properties);

Expand Down Expand Up @@ -154,6 +149,7 @@ private void DrawDistortionProperties(MaterialEditor editor, MaterialProperty[]
}

MaterialEditorUtility.DrawToggleProperty(editor, "Mirror Sampling", _baseMapMirrorSamplingProp.Value);
MaterialEditorUtility.DrawToggleProperty(editor, "Use As Normal Map", _baseMapUnpackNormalProp.Value);
}

private void DrawFlowMapProperties(MaterialEditor editor, MaterialProperty[] properties)
Expand Down Expand Up @@ -210,6 +206,13 @@ private void DrawTransparencyProperties(MaterialEditor editor, MaterialProperty[
}
}

#region Render Settings Material Properties

private readonly Property _cullProp = new(PropertyNames.Cull);
private readonly Property _zTestProp = new(PropertyNames.ZTest);

#endregion

#region Foldout Properties

private BoolEditorPrefsProperty RenderSettingsFoldout { get; set; }
Expand All @@ -222,64 +225,63 @@ private void DrawTransparencyProperties(MaterialEditor editor, MaterialProperty[

#region Distortion Material Properties

private readonly Property _baseMapProp = new Property(PropertyNames.BaseMap);
private readonly Property _baseMapOffsetXCoordProp = new Property(PropertyNames.BaseMapOffsetXCoord);
private readonly Property _baseMapOffsetYCoordProp = new Property(PropertyNames.BaseMapOffsetYCoord);
private readonly Property _baseMapChannelsXProp = new Property(PropertyNames.BaseMapChannelsX);
private readonly Property _baseMapChannelsYProp = new Property(PropertyNames.BaseMapChannelsY);
private readonly Property _baseMapRotationProp = new Property(PropertyNames.BaseMapRotation);
private readonly Property _baseMapRotationCoordProp = new Property(PropertyNames.BaseMapRotationCoord);
private readonly Property _baseMapRotationOffsetsProp = new Property(PropertyNames.BaseMapRotationOffsets);
private readonly Property _baseMapMirrorSamplingProp = new Property(PropertyNames.BaseMapMirrorSampling);
private readonly Property _distortionIntensityProp = new Property(PropertyNames.DistortionIntensity);
private readonly Property _distortionIntensityCoordProp = new Property(PropertyNames.DistortionIntensityCoord);
private readonly Property _baseMapProp = new(PropertyNames.BaseMap);
private readonly Property _baseMapOffsetXCoordProp = new(PropertyNames.BaseMapOffsetXCoord);
private readonly Property _baseMapOffsetYCoordProp = new(PropertyNames.BaseMapOffsetYCoord);
private readonly Property _baseMapChannelsXProp = new(PropertyNames.BaseMapChannelsX);
private readonly Property _baseMapChannelsYProp = new(PropertyNames.BaseMapChannelsY);
private readonly Property _baseMapRotationProp = new(PropertyNames.BaseMapRotation);
private readonly Property _baseMapRotationCoordProp = new(PropertyNames.BaseMapRotationCoord);
private readonly Property _baseMapRotationOffsetsProp = new(PropertyNames.BaseMapRotationOffsets);
private readonly Property _baseMapMirrorSamplingProp = new(PropertyNames.BaseMapMirrorSampling);
private readonly Property _baseMapUnpackNormalProp = new(PropertyNames.BaseMapUnpackNormal);
private readonly Property _distortionIntensityProp = new(PropertyNames.DistortionIntensity);
private readonly Property _distortionIntensityCoordProp = new(PropertyNames.DistortionIntensityCoord);

#endregion

#region Flow Map Material Properties

private readonly Property _flowMapProp = new Property(PropertyNames.FlowMap);
private readonly Property _flowMapOffsetXCoordProp = new Property(PropertyNames.FlowMapOffsetXCoord);
private readonly Property _flowMapOffsetYCoordProp = new Property(PropertyNames.FlowMapOffsetYCoord);
private readonly Property _flowMapChannelsXProp = new Property(PropertyNames.FlowMapChannelsX);
private readonly Property _flowMapChannelsYProp = new Property(PropertyNames.FlowMapChannelsY);
private readonly Property _flowIntensityProp = new Property(PropertyNames.FlowIntensity);
private readonly Property _flowIntensityCoordProp = new Property(PropertyNames.FlowIntensityCoord);
private readonly Property _flowMapTargetProp = new Property(PropertyNames.FlowMapTarget);
private readonly Property _flowMapProp = new(PropertyNames.FlowMap);
private readonly Property _flowMapOffsetXCoordProp = new(PropertyNames.FlowMapOffsetXCoord);
private readonly Property _flowMapOffsetYCoordProp = new(PropertyNames.FlowMapOffsetYCoord);
private readonly Property _flowMapChannelsXProp = new(PropertyNames.FlowMapChannelsX);
private readonly Property _flowMapChannelsYProp = new(PropertyNames.FlowMapChannelsY);
private readonly Property _flowIntensityProp = new(PropertyNames.FlowIntensity);
private readonly Property _flowIntensityCoordProp = new(PropertyNames.FlowIntensityCoord);
private readonly Property _flowMapTargetProp = new(PropertyNames.FlowMapTarget);

#endregion

#region Alpha Transition Material Properties

private readonly Property _alphaTransitionModeProp = new Property(PropertyNames.AlphaTransitionMode);
private readonly Property _alphaTransitionMapProp = new Property(PropertyNames.AlphaTransitionMap);
private readonly Property _alphaTransitionModeProp = new(PropertyNames.AlphaTransitionMode);
private readonly Property _alphaTransitionMapProp = new(PropertyNames.AlphaTransitionMap);

private readonly Property _alphaTransitionMapOffsetXCoordProp =
new Property(PropertyNames.AlphaTransitionMapOffsetXCoord);
new(PropertyNames.AlphaTransitionMapOffsetXCoord);

private readonly Property _alphaTransitionMapOffsetYCoordProp =
new Property(PropertyNames.AlphaTransitionMapOffsetYCoord);
new(PropertyNames.AlphaTransitionMapOffsetYCoord);

private readonly Property _alphaTransitionMapChannelsXProp =
new Property(PropertyNames.AlphaTransitionMapChannelsX);
private readonly Property _alphaTransitionMapChannelsXProp = new(PropertyNames.AlphaTransitionMapChannelsX);

private readonly Property _alphaTransitionProgressProp = new Property(PropertyNames.AlphaTransitionProgress);
private readonly Property _alphaTransitionProgressProp = new(PropertyNames.AlphaTransitionProgress);

private readonly Property _alphaTransitionProgressCoordProp =
new Property(PropertyNames.AlphaTransitionProgressCoord);
private readonly Property _alphaTransitionProgressCoordProp = new(PropertyNames.AlphaTransitionProgressCoord);

private readonly Property _dissolveSharpnessProp = new Property(PropertyNames.DissolveSharpness);
private readonly Property _dissolveSharpnessProp = new(PropertyNames.DissolveSharpness);

#endregion

#region Transparency Material Properties

private readonly Property _softParticlesEnabledProp = new Property(PropertyNames.SoftParticlesEnabled);
private readonly Property _softParticlesIntensityProp = new Property(PropertyNames.SoftParticlesIntensity);
private readonly Property _depthFadeEnabledProp = new Property(PropertyNames.DepthFadeEnabled);
private readonly Property _depthFadeNearProp = new Property(PropertyNames.DepthFadeNear);
private readonly Property _depthFadeFarProp = new Property(PropertyNames.DepthFadeFar);
private readonly Property _depthFadeWidthProp = new Property(PropertyNames.DepthFadeWidth);
private readonly Property _softParticlesEnabledProp = new(PropertyNames.SoftParticlesEnabled);
private readonly Property _softParticlesIntensityProp = new(PropertyNames.SoftParticlesIntensity);
private readonly Property _depthFadeEnabledProp = new(PropertyNames.DepthFadeEnabled);
private readonly Property _depthFadeNearProp = new(PropertyNames.DepthFadeNear);
private readonly Property _depthFadeFarProp = new(PropertyNames.DepthFadeFar);
private readonly Property _depthFadeWidthProp = new(PropertyNames.DepthFadeWidth);

#endregion
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesDistortion.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CBUFFER_START(UnityPerMaterial)
float4 _BaseMapRotationOffsets;
float _DistortionIntensity;
float _DistortionIntensityCoord;
half _BaseMapUnpackNormal;

float4 _FlowMap_ST;
DECLARE_CUSTOM_COORD(_FlowMapOffsetXCoord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Shader "Nova/Particles/Distortion"
_BaseMapRotationCoord("Base Map Rotation Coord", Float) = 0.0
_BaseMapRotationOffsets("Base Map Rotation Offsets", Vector) = (0.0, 0.0, 0.0, 0.0)
_BaseMapMirrorSampling("Base Map Mirror Sampling", Float) = 0
_BaseMapUnpackNormal("Base Map Unpack Normal", Float) = 0
[PowerSlider(3)]_DistortionIntensity("Distortion Intensity", Range(0, 1)) = 0.1
_DistortionIntensityCoord("Distortion Intensity Coord", Range(0, 1)) = 0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ half4 frag(Varyings input) : SV_Target
baseMapSamplerState = sampler_BaseMap;
#endif
half4 distortionSrc = SAMPLE_TEXTURE2D(_BaseMap, baseMapSamplerState, input.baseUv.xy);
if (_BaseMapUnpackNormal)
{
// [???] => [-1, 1]
half3 unpackedNormal = UnpackNormal(distortionSrc);
// [-1, 1] => [0, 1]
distortionSrc = half4((unpackedNormal + 1) * 0.5f, 1);
}

half2 distortion;
distortion.x = distortionSrc[(uint)_BaseMapChannelsX];
distortion.y = distortionSrc[(uint)_BaseMapChannelsY];
Expand Down
Binary file added Documentation~/Images/distortion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation~/Images/flow_mapping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For more information, please refer to the following documents, [Samples](Assets/
- [Distortion Shader](#distortion-shader)
- [Render Settings](#render-settings-2)
- [Distortion](#distortion)
- [Flow Map](#flow-map-1)
- [Flow Mapping](#flow-mapping)
- [Alpha Transition](#alpha-transition-1)
- [Transparency](#transparency-1)
- [Uber Unlit/Lit shaders( for uGUI )](#uber-unlitlit-shaders-for-ugui-)
Expand Down Expand Up @@ -1124,7 +1124,7 @@ You can set ZTest value.
Distortion controls how it is distorted.

<p align="center">
<img width="60%" src="https://user-images.githubusercontent.com/106138524/173484623-01bec5e8-68ea-4afe-8679-90a31a3fa62c.png" alt="Distortion"><br>
<img width="60%" src="Documentation~/Images/distortion.png" alt="Distortion"><br>
<font color="grey">Distortion</font>
</p>

Expand Down Expand Up @@ -1165,14 +1165,19 @@ Shifts the center coordinate of rotation.
If true, mirrors the texture to create a repeating pattern.
</p>
</td></tr>
<tr><td colspan="3"><b>Use As Normal Map</b></td><td>
<p>
If true, the Texture Type is treated as a Normal Map and will be unpacked for sampling.
</p>
</td></tr>
</tbody>
</table>

#### Flow Map
#### Flow Mapping
You can use the Flow Map to distort the Distortion Map to the specified directions.

<p align="center">
<img width="60%" src="https://user-images.githubusercontent.com/106138524/173484646-d134aad0-3e2d-45c3-b4ae-7017d5a07801.png" alt="Flow Map"><br>
<img width="60%" src="Documentation~/Images/flow_mapping.png" alt="Flow Map"><br>
<font color="grey">Flow Map</font>
</p>

Expand Down
11 changes: 8 additions & 3 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
- [Distortionシェーダ](#distortion%E3%82%B7%E3%82%A7%E3%83%BC%E3%83%80)
- [Render Settings](#render-settings-2)
- [Distortion](#distortion)
- [Flow Map](#flow-map-1)
- [Flow Mapping](#flow-mapping)
- [Alpha Transition](#alpha-transition-1)
- [Transparency](#transparency-1)
- [Uber Unlit/Litシェーダ( for uGUI )](#uber-unlitlit%E3%82%B7%E3%82%A7%E3%83%BC%E3%83%80-for-ugui-)
Expand Down Expand Up @@ -1133,7 +1133,7 @@ ZTestを設定できます。
Distortionでは歪ませ方を設定できます。

<p align="center">
<img width="60%" src="https://user-images.githubusercontent.com/106138524/173495634-33aa9641-ee8e-4f15-9707-0753acceffb7.png" alt="Distortion"><br>
<img width="60%" src="Documentation~/Images/distortion.png" alt="Distortion"><br>
<font color="grey">Distortion</font>
</p>

Expand Down Expand Up @@ -1174,10 +1174,15 @@ Distortionでは歪ませ方を設定できます。
チェックをつけるとテクスチャがミラーサンプリングされます。
</p>
</td></tr>
<tr><td colspan="3"><b>Use As Normal Map</b></td><td>
<p>
チェックをつけるとTexture TypeをNormal Mapとみなし、Unpackしてサンプリングされます。
</p>
</td></tr>
</tbody>
</table>

#### Flow Map
#### Flow Mapping
Flow Mapを使うとディストーションマップを指定した方向に歪ませることができます。

<p align="center">
Expand Down

0 comments on commit c62a857

Please sign in to comment.