Skip to content

Commit

Permalink
1.62
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Jan 2, 2022
1 parent 3609300 commit 4d08865
Show file tree
Hide file tree
Showing 30 changed files with 519 additions and 189 deletions.
1 change: 1 addition & 0 deletions Assets/Effekseer/Editor/EffekseerAssetPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void OnPostprocessAllAssets(
var tp = new EffekseerMaterialAsset.TextureProperty();
tp.Name = t.Name;
tp.UniformName = t.UniformName;
tp.Type = (EffekseerMaterialAsset.TextureType)EffekseerTool.Utl.TextureType.Color;
importingAsset.Textures.Add(tp);
}

Expand Down
4 changes: 3 additions & 1 deletion Assets/Effekseer/Editor/EffekseerEmitterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ void CallSceneGUI()

GUILayout.BeginHorizontal();
GUILayout.Label("Speed", GUILayout.Width(50));
emitter.speed = GUILayout.HorizontalSlider(emitter.speed, 0.0f, 2.0f);
emitter.speed = GUILayout.HorizontalSlider(emitter.speed, 0.0f, 2.0f, GUILayout.Width(50));
emitter.speed = EditorGUILayout.FloatField(emitter.speed, GUILayout.Width(50));
emitter.speed = Mathf.Clamp(emitter.speed, 0, 2);
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Expand Down
25 changes: 20 additions & 5 deletions Assets/Effekseer/Materials/EffekseerShaderAdCommonPS.cginc
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@

#include "EffekseerShader_Linear_sRGB.cginc"

void ApplyFlipbook(inout float4 dst,
const Texture2D t,
const SamplerState s,
const float4 flipbookParameter,
const float4 vcolor,
const float2 nextUV,
float flipbookRate)
float flipbookRate,
bool convertFromSRGB)
{
if (flipbookParameter.x > 0)
{
float4 NextPixelColor = t.Sample(s, nextUV) * vcolor;
float4 sampledColor = t.Sample(s, nextUV);

if (convertFromSRGB) {
sampledColor = ConvertFromSRGBTexture(sampledColor, convertFromSRGB);
}

float4 NextPixelColor = sampledColor * vcolor;

// lerp
if (flipbookParameter.y == 1)
Expand Down Expand Up @@ -43,10 +52,16 @@ void ApplyTextureBlending(inout float4 dstColor, const float4 blendColor, const
}
}


float2 UVDistortionOffset(const Texture2D t, const SamplerState s, float2 uv, float2 uvInversed)
float2 UVDistortionOffset(const Texture2D t, const SamplerState s, float2 uv, float2 uvInversed, bool convertFromSRGB)
{
float2 UVOffset = t.Sample(s, uv).rg * 2.0 - 1.0;
float4 sampledColor = t.Sample(s, uv);

if (convertFromSRGB)
{
sampledColor = ConvertFromSRGBTexture(sampledColor, convertFromSRGB);
}

float2 UVOffset = sampledColor.rg * 2.0 - 1.0;
UVOffset.y *= -1.0;
UVOffset.y = uvInversed.x + uvInversed.y * UVOffset.y;
return UVOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ float4 frag(const PS_Input Input)

AdvancedParameter advancedParam = DisolveAdvancedParameter(Input);

float2 UVOffset = UVDistortionOffset(_uvDistortionTex, sampler_uvDistortionTex, advancedParam.UVDistortionUV, fUVDistortionParameter.zw);
float2 UVOffset = UVDistortionOffset(_uvDistortionTex, sampler_uvDistortionTex, advancedParam.UVDistortionUV, fUVDistortionParameter.zw, false);
UVOffset *= fUVDistortionParameter.x;

float4 Output = _colorTex.Sample(sampler_colorTex, Input.UV_Others + UVOffset);

Output.a = Output.a * Input.Color.a;

ApplyFlipbook(Output, _colorTex, sampler_colorTex, fFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate);
ApplyFlipbook(Output, _colorTex, sampler_colorTex, fFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate, false);

// apply alpha texture
float4 AlphaTexColor = _alphaTex.Sample(sampler_alphaTex, advancedParam.AlphaUV + UVOffset);
Output.a *= AlphaTexColor.r * AlphaTexColor.a;

// blend texture uv offset
float2 BlendUVOffset = UVDistortionOffset(_blendUVDistortionTex, sampler_blendUVDistortionTex, advancedParam.BlendUVDistortionUV, fUVDistortionParameter.zw);
float2 BlendUVOffset = UVDistortionOffset(_blendUVDistortionTex, sampler_blendUVDistortionTex, advancedParam.BlendUVDistortionUV, fUVDistortionParameter.zw, false);
BlendUVOffset *= fUVDistortionParameter.y;

float4 BlendTextureColor = _blendTex.Sample(sampler_blendTex, advancedParam.BlendUV + BlendUVOffset);
Expand Down
19 changes: 11 additions & 8 deletions Assets/Effekseer/Materials/EffekseerShaderAdLitUnlitPS.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ struct PS_Input

#include "EffekseerShaderAdCommonPS.cginc"
#include "EffekseerShaderSoftParticlePS.cginc"
#include "EffekseerShader_Linear_sRGB.cginc"

float4 frag(const PS_Input Input)
: SV_Target
{
bool convColorSpace = convertColorSpace != 0.0f;

float4 fCameraFrontDirection = -float4(UNITY_MATRIX_V[2].xyz, 1.0);

AdvancedParameter advancedParam = DisolveAdvancedParameter(Input);

float2 UVOffset = UVDistortionOffset(_uvDistortionTex, sampler_uvDistortionTex, advancedParam.UVDistortionUV, fUVDistortionParameter.zw);
float2 UVOffset = UVDistortionOffset(_uvDistortionTex, sampler_uvDistortionTex, advancedParam.UVDistortionUV, fUVDistortionParameter.zw, convColorSpace);
UVOffset *= fUVDistortionParameter.x;

float4 Output = _colorTex.Sample(sampler_colorTex, Input.UV_Others.xy + UVOffset) * Input.Color;
float4 Output = ConvertFromSRGBTexture(_colorTex.Sample(sampler_colorTex, Input.UV_Others.xy + UVOffset), convColorSpace) * Input.Color;

#if ENABLE_LIGHTING
half3 texNormal = (_normalTex.Sample(sampler_normalTex, Input.UV_Others.xy + UVOffset).xyz - 0.5) * 2.0;
Expand All @@ -128,18 +131,18 @@ float4 frag(const PS_Input Input)
half3x3((half3)Input.WorldT, (half3)Input.WorldB, (half3)Input.WorldN)));
#endif

ApplyFlipbook(Output, _colorTex, sampler_colorTex, fFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate);
ApplyFlipbook(Output, _colorTex, sampler_colorTex, fFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate, convColorSpace);

// apply alpha texture
float4 AlphaTexColor = _alphaTex.Sample(sampler_alphaTex, advancedParam.AlphaUV + UVOffset);
float4 AlphaTexColor = ConvertFromSRGBTexture(_alphaTex.Sample(sampler_alphaTex, advancedParam.AlphaUV + UVOffset), convColorSpace);
Output.a *= AlphaTexColor.r * AlphaTexColor.a;

// blend texture uv offset
float2 BlendUVOffset = UVDistortionOffset(_blendUVDistortionTex, sampler_blendUVDistortionTex, advancedParam.BlendUVDistortionUV, fUVDistortionParameter.zw);
float2 BlendUVOffset = UVDistortionOffset(_blendUVDistortionTex, sampler_blendUVDistortionTex, advancedParam.BlendUVDistortionUV, fUVDistortionParameter.zw, convColorSpace);
BlendUVOffset *= fUVDistortionParameter.y;

float4 BlendTextureColor = _blendTex.Sample(sampler_blendTex, advancedParam.BlendUV + BlendUVOffset);
float4 BlendAlphaTextureColor = _blendAlphaTex.Sample(sampler_blendAlphaTex, advancedParam.BlendAlphaUV + BlendUVOffset);
float4 BlendTextureColor = ConvertFromSRGBTexture(_blendTex.Sample(sampler_blendTex, advancedParam.BlendUV + BlendUVOffset), convColorSpace);
float4 BlendAlphaTextureColor = ConvertFromSRGBTexture(_blendAlphaTex.Sample(sampler_blendAlphaTex, advancedParam.BlendAlphaUV + BlendUVOffset), convColorSpace);
BlendTextureColor.a *= BlendAlphaTextureColor.r * BlendAlphaTextureColor.a;

ApplyTextureBlending(Output, BlendTextureColor, fBlendTextureParameter.x);
Expand Down Expand Up @@ -211,5 +214,5 @@ float4 frag(const PS_Input Input)
Output.rgb,
ceil((Output.a - advancedParam.AlphaThreshold) - fEdgeParameter.x));

return Output;
return ConvertToScreen(Output, convColorSpace);
}
2 changes: 2 additions & 0 deletions Assets/Effekseer/Materials/EffekseerShaderCommon.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ struct SpriteAdvancedParameter
float FlipbookIndexAndNextRate;
float AlphaThreshold;
};

float convertColorSpace;
8 changes: 5 additions & 3 deletions Assets/Effekseer/Materials/EffekseerShaderLitUnlitPS.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ struct PS_Input
};

#include "EffekseerShaderSoftParticlePS.cginc"
#include "EffekseerShader_Linear_sRGB.cginc"

float4 frag(const PS_Input Input)
: SV_Target
{
float4 Output = _colorTex.Sample(sampler_colorTex, Input.UV) * Input.Color;
bool convColorSpace = convertColorSpace != 0.0f;

float4 Output = ConvertFromSRGBTexture(_colorTex.Sample(sampler_colorTex, Input.UV), convColorSpace) * Input.Color;

#if ENABLE_LIGHTING
half3 texNormal = (_normalTex.Sample(sampler_normalTex, Input.UV).xyz - 0.5) * 2.0;
Expand Down Expand Up @@ -106,9 +109,8 @@ float4 frag(const PS_Input Input)
}
#endif


if (Output.a == 0.0)
discard;

return Output;
return ConvertToScreen(Output, convColorSpace);
}
60 changes: 60 additions & 0 deletions Assets/Effekseer/Materials/EffekseerShader_Linear_sRGB.cginc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef LINEAR_SRGB_FX
#define LINEAR_SRGB_FX

#define FLT_EPSILON 1.192092896e-07f

float3 PositivePow(float3 base, float3 power)
{
return pow(max(abs(base), float3(FLT_EPSILON, FLT_EPSILON, FLT_EPSILON)), power);
}

// based on http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html?m=1
float3 SRGBToLinear(float3 c)
{
return min(c, c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878));
}

float4 SRGBToLinear(float4 c)
{
return float4(SRGBToLinear(c.rgb), c.a);
}

float3 LinearToSRGB(float3 c)
{
return max(1.055 * PositivePow(c, 0.416666667) - 0.055, 0.0);
}

float4 LinearToSRGB(float4 c)
{
return float4(LinearToSRGB(c.rgb), c.a);
}

float4 ConvertFromSRGBTexture(float4 c, bool isValid)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return c;
#else
if (!isValid)
{
return c;
}

return LinearToSRGB(c);
#endif
}

float4 ConvertToScreen(float4 c, bool isValid)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return c;
#else
if (!isValid)
{
return c;
}

return SRGBToLinear(c);
#endif
}

#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/WebGL/libEffekseerUnity.bc
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/iOS/libEffekseerUnity.a
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/x86/EffekseerUnity.dll
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/x86_64/EffekseerUnity.dll
Binary file not shown.
21 changes: 21 additions & 0 deletions Assets/Effekseer/Resources/EffekseerDependentAssets.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 14b4767e3be63d246ac675d4f9c0d467, type: 3}
m_Name: EffekseerDependentAssets
m_EditorClassIdentifier:
texture2DArrayBlitMaterial: {fileID: 4800000, guid: 67d08a86aa6a44b41bf877601419e9d7,
type: 3}
texture2DBlitMaterial: {fileID: 4800000, guid: 481306851e1e5834bb2c03a0fb529629,
type: 3}
grabDepthShader: {fileID: 4800000, guid: 90ee1bc0a4dae04408b460d655b419ef, type: 3}
fixedShader: {fileID: 4800000, guid: addc52f57a6457a41952f47196de99d8, type: 3}
fakeMaterial: {fileID: 4800000, guid: 7c7fc95c6efbe1149b2f9f4747030f6e, type: 3}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Effekseer/Scripts/Effekseer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal static class Plugin
#endif

[DllImport(pluginName)]
public static extern void EffekseerInit(int maxInstances, int maxSquares, int isRightHandedCoordinate, int reversedDepth, int threadCount, int rendererType);
public static extern void EffekseerInit(int maxInstances, int maxSquares, int reversedDepth, int maintainGammaColor, int isRightHandedCoordinate, int threadCount, int rendererType);

[DllImport(pluginName)]
public static extern void EffekseerTerm();
Expand Down
Loading

0 comments on commit 4d08865

Please sign in to comment.