Skip to content

Commit 6f3babe

Browse files
CopilotLuticaCANARD
andcommitted
Fix ArtisticEffects shader bugs, add quick shader selector, hide unused parameters
Co-authored-by: LuticaCANARD <80238084+LuticaCANARD@users.noreply.github.com>
1 parent 6718bba commit 6f3babe

6 files changed

Lines changed: 187 additions & 14 deletions

File tree

Packages/luticalab.core/Languages/English.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@
144144
"value_convert": "Value (Brightness) Convert",
145145
"hue_offset": "Hue Offset",
146146
"saturation_offset": "Saturation Offset",
147-
"value_offset": "Value (Brightness) Offset"
147+
"value_offset": "Value (Brightness) Offset",
148+
149+
"quick_shader_select": "Quick Shader Selection",
150+
"select_shader": "Select Shader",
151+
"oilpaint_warning": "⚠️ Oil Paint effect is computationally expensive. Adjust parameters first, then click Apply to render. Real-time preview is disabled to prevent performance issues.",
152+
"apply_oilpaint": "Apply Oil Paint Effect"
148153
}
149154

150155
}

Packages/luticalab.core/Languages/Japanese.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@
147147
"value_convert": "明度(輝度)変換",
148148
"hue_offset": "色相オフセット",
149149
"saturation_offset": "彩度オフセット",
150-
"value_offset": "明度(輝度)オフセット"
150+
"value_offset": "明度(輝度)オフセット",
151+
152+
"quick_shader_select": "クイックシェーダー選択",
153+
"select_shader": "シェーダーを選択",
154+
"oilpaint_warning": "⚠️ オイルペイント効果は計算負荷が高いです。まずパラメータを調整してから、適用ボタンをクリックしてレンダリングしてください。パフォーマンスの問題を防ぐため、リアルタイムプレビューは無効になっています。",
155+
"apply_oilpaint": "オイルペイント効果を適用"
151156
}
152157

153158
}

Packages/luticalab.core/Languages/Korean.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@
143143
"value_convert": "명도(밝기) 변환",
144144
"hue_offset": "색상 오프셋",
145145
"saturation_offset": "채도 오프셋",
146-
"value_offset": "명도(밝기) 오프셋"
146+
"value_offset": "명도(밝기) 오프셋",
147+
148+
"quick_shader_select": "빠른 셰이더 선택",
149+
"select_shader": "셰이더 선택",
150+
"oilpaint_warning": "⚠️ 오일 페인트 효과는 계산 부하가 큽니다. 먼저 파라미터를 조정한 다음 적용 버튼을 클릭하여 렌더링하세요. 성능 문제를 방지하기 위해 실시간 미리보기가 비활성화되었습니다.",
151+
"apply_oilpaint": "오일 페인트 효과 적용"
147152
}
148153
}

Packages/luticalab.texturecocktail/Editor/Content/ArtisticEffects.cs

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,29 @@ public override void OnGUI()
6363

6464
GUILayout.Space(10);
6565

66-
// Effect-specific settings
66+
// Effect-specific settings - show only relevant parameters
6767
if (currentEffect != ArtisticEffect.None)
6868
{
6969
_showEffectSettings = EditorGUILayout.BeginFoldoutHeaderGroup(_showEffectSettings,
7070
LanguageDisplayer.Instance.GetTranslatedLanguage("effect_settings"));
7171
if (_showEffectSettings)
7272
{
73-
baseWindow.ShowShaderInfo();
73+
ShowEffectSpecificParameters();
7474
}
7575
EditorGUILayout.EndFoldoutHeaderGroup();
7676
}
7777

78+
// Warning for Oil Paint
79+
if (currentEffect == ArtisticEffect.OilPaint)
80+
{
81+
EditorGUILayout.HelpBox(LanguageDisplayer.Instance.GetTranslatedLanguage("oilpaint_warning"), MessageType.Warning);
82+
83+
if (GUILayout.Button(LanguageDisplayer.Instance.GetTranslatedLanguage("apply_oilpaint"), GUILayout.Height(35)))
84+
{
85+
baseWindow.CompileShader();
86+
}
87+
}
88+
7889
// Preview
7990
_showPreview = EditorGUILayout.BeginFoldoutHeaderGroup(_showPreview,
8091
LanguageDisplayer.Instance.GetTranslatedLanguage("preview"));
@@ -84,9 +95,12 @@ public override void OnGUI()
8495

8596
// Quick actions
8697
EditorGUILayout.BeginHorizontal();
87-
if (GUILayout.Button(LanguageDisplayer.Instance.GetTranslatedLanguage("apply_quick"), GUILayout.Height(30)))
98+
if (currentEffect != ArtisticEffect.OilPaint)
8899
{
89-
baseWindow.CompileShader();
100+
if (GUILayout.Button(LanguageDisplayer.Instance.GetTranslatedLanguage("apply_quick"), GUILayout.Height(30)))
101+
{
102+
baseWindow.CompileShader();
103+
}
90104
}
91105
if (GUILayout.Button(LanguageDisplayer.Instance.GetTranslatedLanguage("save_texture"), GUILayout.Height(30)))
92106
{
@@ -99,6 +113,92 @@ public override void OnGUI()
99113
GUILayout.EndScrollView();
100114
}
101115

116+
private void ShowEffectSpecificParameters()
117+
{
118+
var material = GetMaterial();
119+
if (material == null) return;
120+
121+
EditorGUI.BeginChangeCheck();
122+
123+
switch (currentEffect)
124+
{
125+
case ArtisticEffect.Pixelate:
126+
if (material.HasProperty("_PixelSize"))
127+
{
128+
float pixelSize = material.GetFloat("_PixelSize");
129+
pixelSize = EditorGUILayout.Slider("Pixel Size", pixelSize, 1, 100);
130+
material.SetFloat("_PixelSize", pixelSize);
131+
}
132+
break;
133+
134+
case ArtisticEffect.Posterize:
135+
if (material.HasProperty("_ColorLevels"))
136+
{
137+
float colorLevels = material.GetFloat("_ColorLevels");
138+
colorLevels = EditorGUILayout.Slider("Color Levels", colorLevels, 2, 256);
139+
material.SetFloat("_ColorLevels", colorLevels);
140+
}
141+
break;
142+
143+
case ArtisticEffect.Halftone:
144+
if (material.HasProperty("_DotSize"))
145+
{
146+
float dotSize = material.GetFloat("_DotSize");
147+
dotSize = EditorGUILayout.Slider("Dot Size", dotSize, 1, 20);
148+
material.SetFloat("_DotSize", dotSize);
149+
}
150+
if (material.HasProperty("_DotAngle"))
151+
{
152+
float dotAngle = material.GetFloat("_DotAngle");
153+
dotAngle = EditorGUILayout.Slider("Dot Angle", dotAngle, 0, 360);
154+
material.SetFloat("_DotAngle", dotAngle);
155+
}
156+
break;
157+
158+
case ArtisticEffect.OilPaint:
159+
if (material.HasProperty("_Radius"))
160+
{
161+
float radius = material.GetFloat("_Radius");
162+
radius = EditorGUILayout.Slider("Oil Paint Radius", radius, 1, 10);
163+
material.SetFloat("_Radius", radius);
164+
}
165+
break;
166+
167+
case ArtisticEffect.Emboss:
168+
if (material.HasProperty("_EmbossStrength"))
169+
{
170+
float embossStrength = material.GetFloat("_EmbossStrength");
171+
embossStrength = EditorGUILayout.Slider("Emboss Strength", embossStrength, 0, 5);
172+
material.SetFloat("_EmbossStrength", embossStrength);
173+
}
174+
break;
175+
176+
case ArtisticEffect.Cartoon:
177+
if (material.HasProperty("_EdgeThreshold"))
178+
{
179+
float edgeThreshold = material.GetFloat("_EdgeThreshold");
180+
edgeThreshold = EditorGUILayout.Slider("Edge Threshold", edgeThreshold, 0, 1);
181+
material.SetFloat("_EdgeThreshold", edgeThreshold);
182+
}
183+
if (material.HasProperty("_ColorSteps"))
184+
{
185+
float colorSteps = material.GetFloat("_ColorSteps");
186+
colorSteps = EditorGUILayout.Slider("Color Steps", colorSteps, 2, 10);
187+
material.SetFloat("_ColorSteps", colorSteps);
188+
}
189+
break;
190+
}
191+
192+
if (EditorGUI.EndChangeCheck())
193+
{
194+
// Only auto-compile for effects other than Oil Paint
195+
if (currentEffect != ArtisticEffect.OilPaint)
196+
{
197+
baseWindow.CompileShader();
198+
}
199+
}
200+
}
201+
102202
private string GetEffectDescription()
103203
{
104204
switch (currentEffect)

Packages/luticalab.texturecocktail/Editor/TextureCocktail.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,63 @@ public static void ShowWindow()
2929
private bool _shaderChanged = false;
3030
private readonly Dictionary<string,bool> _keywordOnOff = new Dictionary<string, bool>();
3131
const string _mainTexProperty = "_MainTex";
32+
33+
// Quick shader selection
34+
private static readonly string[] _quickShaderNames = new string[]
35+
{
36+
"None",
37+
"FastImageConverter",
38+
"FeatureExtractor",
39+
"ColorCorrection",
40+
"TextureBlender",
41+
"ArtisticEffects",
42+
"ImageFilter (HSVMover)",
43+
"ImageSync",
44+
"InverseFilter",
45+
"NormalMapGenerator"
46+
};
47+
48+
private static readonly string[] _quickShaderPaths = new string[]
49+
{
50+
"",
51+
"Hidden/FastImageConverter",
52+
"Hidden/FeatureExtractor",
53+
"Hidden/ColorCorrection",
54+
"Hidden/TextureBlender",
55+
"Hidden/ArtisticEffects",
56+
"Hidden/ImageFilter",
57+
"Hidden/ImageSync",
58+
"Hidden/ImageEffect",
59+
"Hidden/NormalMapGenerator"
60+
};
61+
62+
private int _selectedQuickShaderIndex = 0;
63+
3264
private void OnGUI()
3365
{
3466
GUILayout.Label("TextureCocktail", EditorStyles.boldLabel);
67+
68+
// Quick shader selector
69+
GUILayout.Label(LanguageDisplayer.Instance.GetTranslatedLanguage("quick_shader_select"), EditorStyles.boldLabel);
70+
int newShaderIndex = EditorGUILayout.Popup(LanguageDisplayer.Instance.GetTranslatedLanguage("select_shader"), _selectedQuickShaderIndex, _quickShaderNames);
71+
if (newShaderIndex != _selectedQuickShaderIndex)
72+
{
73+
_selectedQuickShaderIndex = newShaderIndex;
74+
if (newShaderIndex > 0)
75+
{
76+
var shader = Shader.Find(_quickShaderPaths[newShaderIndex]);
77+
if (shader != null)
78+
{
79+
OnShaderChange(shader);
80+
}
81+
}
82+
else
83+
{
84+
OnShaderChange(null);
85+
}
86+
}
87+
88+
GUILayout.Space(5);
3589

3690
// Shader field - clickable when assigned, selectable when not
3791
EditorGUILayout.BeginHorizontal();

Packages/luticalab.texturecocktail/Shader/Image/ArtisticEffects.shader

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ Shader "Hidden/ArtisticEffects"
7878
// Pixelate effect
7979
fixed4 pixelate(float2 uv, float pixelSize)
8080
{
81-
float2 pixelUV = floor(uv * _MainTex_TexelSize.zw / pixelSize) * pixelSize / _MainTex_TexelSize.zw;
81+
// Use actual pixel size in texture space
82+
float2 pixelUV = floor(uv * _MainTex_TexelSize.zw / max(pixelSize, 1.0)) * max(pixelSize, 1.0) / _MainTex_TexelSize.zw;
8283
return tex2D(_MainTex, pixelUV);
8384
}
8485

8586
// Posterize effect
8687
fixed4 posterize(float2 uv, float levels)
8788
{
8889
fixed4 col = tex2D(_MainTex, uv);
89-
col.rgb = floor(col.rgb * levels) / levels;
90+
// Ensure levels is at least 2 to avoid division by zero
91+
float validLevels = max(levels, 2.0);
92+
col.rgb = floor(col.rgb * validLevels) / validLevels;
9093
return col;
9194
}
9295

@@ -171,6 +174,10 @@ Shader "Hidden/ArtisticEffects"
171174
{
172175
fixed4 col = tex2D(_MainTex, uv);
173176

177+
// Color quantization - ensure colorSteps is valid
178+
float validSteps = max(colorSteps, 2.0);
179+
col.rgb = floor(col.rgb * validSteps) / validSteps;
180+
174181
// Edge detection
175182
float edge = 0;
176183
for (int y = -1; y <= 1; y++)
@@ -185,13 +192,10 @@ Shader "Hidden/ArtisticEffects"
185192
}
186193
edge /= 8.0;
187194

188-
// Color quantization
189-
col.rgb = floor(col.rgb * colorSteps) / colorSteps;
190-
191-
// Apply edge
195+
// Apply edge - darken edge pixels
192196
if (edge > edgeThreshold)
193197
{
194-
col.rgb = float3(0, 0, 0);
198+
col.rgb = lerp(col.rgb, float3(0, 0, 0), 0.8);
195199
}
196200

197201
return col;

0 commit comments

Comments
 (0)