omgkit 2.13.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -10
- package/package.json +2 -2
- package/plugin/agents/api-designer.md +5 -0
- package/plugin/agents/architect.md +8 -0
- package/plugin/agents/brainstormer.md +4 -0
- package/plugin/agents/cicd-manager.md +6 -0
- package/plugin/agents/code-reviewer.md +6 -0
- package/plugin/agents/copywriter.md +2 -0
- package/plugin/agents/data-engineer.md +255 -0
- package/plugin/agents/database-admin.md +10 -0
- package/plugin/agents/debugger.md +10 -0
- package/plugin/agents/devsecops.md +314 -0
- package/plugin/agents/docs-manager.md +4 -0
- package/plugin/agents/domain-decomposer.md +181 -0
- package/plugin/agents/embedded-systems.md +397 -0
- package/plugin/agents/fullstack-developer.md +12 -0
- package/plugin/agents/game-systems-designer.md +375 -0
- package/plugin/agents/git-manager.md +10 -0
- package/plugin/agents/journal-writer.md +2 -0
- package/plugin/agents/ml-engineer.md +284 -0
- package/plugin/agents/observability-engineer.md +353 -0
- package/plugin/agents/oracle.md +9 -0
- package/plugin/agents/performance-engineer.md +290 -0
- package/plugin/agents/pipeline-architect.md +6 -0
- package/plugin/agents/planner.md +12 -0
- package/plugin/agents/platform-engineer.md +325 -0
- package/plugin/agents/project-manager.md +3 -0
- package/plugin/agents/researcher.md +5 -0
- package/plugin/agents/scientific-computing.md +426 -0
- package/plugin/agents/scout.md +3 -0
- package/plugin/agents/security-auditor.md +7 -0
- package/plugin/agents/sprint-master.md +17 -0
- package/plugin/agents/tester.md +10 -0
- package/plugin/agents/ui-ux-designer.md +12 -0
- package/plugin/agents/vulnerability-scanner.md +6 -0
- package/plugin/commands/data/pipeline.md +47 -0
- package/plugin/commands/data/quality.md +49 -0
- package/plugin/commands/domain/analyze.md +34 -0
- package/plugin/commands/domain/map.md +41 -0
- package/plugin/commands/game/balance.md +56 -0
- package/plugin/commands/game/optimize.md +62 -0
- package/plugin/commands/iot/provision.md +58 -0
- package/plugin/commands/ml/evaluate.md +47 -0
- package/plugin/commands/ml/train.md +48 -0
- package/plugin/commands/perf/benchmark.md +54 -0
- package/plugin/commands/perf/profile.md +49 -0
- package/plugin/commands/platform/blueprint.md +56 -0
- package/plugin/commands/security/audit.md +54 -0
- package/plugin/commands/security/scan.md +55 -0
- package/plugin/commands/sre/dashboard.md +53 -0
- package/plugin/registry.yaml +787 -0
- package/plugin/skills/ai-ml/experiment-tracking/SKILL.md +338 -0
- package/plugin/skills/ai-ml/feature-stores/SKILL.md +340 -0
- package/plugin/skills/ai-ml/llm-ops/SKILL.md +454 -0
- package/plugin/skills/ai-ml/ml-pipelines/SKILL.md +390 -0
- package/plugin/skills/ai-ml/model-monitoring/SKILL.md +398 -0
- package/plugin/skills/ai-ml/model-serving/SKILL.md +386 -0
- package/plugin/skills/event-driven/cqrs-patterns/SKILL.md +348 -0
- package/plugin/skills/event-driven/event-sourcing/SKILL.md +334 -0
- package/plugin/skills/event-driven/kafka-deep/SKILL.md +252 -0
- package/plugin/skills/event-driven/saga-orchestration/SKILL.md +335 -0
- package/plugin/skills/event-driven/schema-registry/SKILL.md +328 -0
- package/plugin/skills/event-driven/stream-processing/SKILL.md +313 -0
- package/plugin/skills/game/game-audio/SKILL.md +446 -0
- package/plugin/skills/game/game-networking/SKILL.md +490 -0
- package/plugin/skills/game/godot-patterns/SKILL.md +413 -0
- package/plugin/skills/game/shader-programming/SKILL.md +492 -0
- package/plugin/skills/game/unity-patterns/SKILL.md +488 -0
- package/plugin/skills/iot/device-provisioning/SKILL.md +405 -0
- package/plugin/skills/iot/edge-computing/SKILL.md +369 -0
- package/plugin/skills/iot/industrial-protocols/SKILL.md +438 -0
- package/plugin/skills/iot/mqtt-deep/SKILL.md +418 -0
- package/plugin/skills/iot/ota-updates/SKILL.md +426 -0
- package/plugin/skills/microservices/api-gateway-patterns/SKILL.md +201 -0
- package/plugin/skills/microservices/circuit-breaker-patterns/SKILL.md +246 -0
- package/plugin/skills/microservices/contract-testing/SKILL.md +284 -0
- package/plugin/skills/microservices/distributed-tracing/SKILL.md +246 -0
- package/plugin/skills/microservices/service-discovery/SKILL.md +304 -0
- package/plugin/skills/microservices/service-mesh/SKILL.md +181 -0
- package/plugin/skills/mobile-advanced/mobile-ci-cd/SKILL.md +407 -0
- package/plugin/skills/mobile-advanced/mobile-security/SKILL.md +403 -0
- package/plugin/skills/mobile-advanced/offline-first/SKILL.md +473 -0
- package/plugin/skills/mobile-advanced/push-notifications/SKILL.md +494 -0
- package/plugin/skills/mobile-advanced/react-native-deep/SKILL.md +374 -0
- package/plugin/skills/simulation/numerical-methods/SKILL.md +434 -0
- package/plugin/skills/simulation/parallel-computing/SKILL.md +382 -0
- package/plugin/skills/simulation/physics-engines/SKILL.md +377 -0
- package/plugin/skills/simulation/validation-verification/SKILL.md +479 -0
- package/plugin/skills/simulation/visualization-scientific/SKILL.md +365 -0
- package/plugin/stdrules/ALIGNMENT_PRINCIPLE.md +240 -0
- package/plugin/workflows/ai-engineering/agent-development.md +3 -3
- package/plugin/workflows/ai-engineering/fine-tuning.md +3 -3
- package/plugin/workflows/ai-engineering/model-evaluation.md +3 -3
- package/plugin/workflows/ai-engineering/prompt-engineering.md +2 -2
- package/plugin/workflows/ai-engineering/rag-development.md +4 -4
- package/plugin/workflows/ai-ml/data-pipeline.md +188 -0
- package/plugin/workflows/ai-ml/experiment-cycle.md +203 -0
- package/plugin/workflows/ai-ml/feature-engineering.md +208 -0
- package/plugin/workflows/ai-ml/model-deployment.md +199 -0
- package/plugin/workflows/ai-ml/monitoring-setup.md +227 -0
- package/plugin/workflows/api/api-design.md +1 -1
- package/plugin/workflows/api/api-testing.md +2 -2
- package/plugin/workflows/content/technical-docs.md +1 -1
- package/plugin/workflows/database/migration.md +1 -1
- package/plugin/workflows/database/optimization.md +1 -1
- package/plugin/workflows/database/schema-design.md +3 -3
- package/plugin/workflows/development/bug-fix.md +3 -3
- package/plugin/workflows/development/code-review.md +2 -1
- package/plugin/workflows/development/feature.md +3 -3
- package/plugin/workflows/development/refactor.md +2 -2
- package/plugin/workflows/event-driven/consumer-groups.md +190 -0
- package/plugin/workflows/event-driven/event-storming.md +172 -0
- package/plugin/workflows/event-driven/replay-testing.md +186 -0
- package/plugin/workflows/event-driven/saga-implementation.md +206 -0
- package/plugin/workflows/event-driven/schema-evolution.md +173 -0
- package/plugin/workflows/fullstack/authentication.md +4 -4
- package/plugin/workflows/fullstack/full-feature.md +4 -4
- package/plugin/workflows/game-dev/content-pipeline.md +218 -0
- package/plugin/workflows/game-dev/platform-submission.md +263 -0
- package/plugin/workflows/game-dev/playtesting.md +237 -0
- package/plugin/workflows/game-dev/prototype-to-production.md +205 -0
- package/plugin/workflows/microservices/contract-first.md +151 -0
- package/plugin/workflows/microservices/distributed-tracing.md +166 -0
- package/plugin/workflows/microservices/domain-decomposition.md +123 -0
- package/plugin/workflows/microservices/integration-testing.md +149 -0
- package/plugin/workflows/microservices/service-mesh-setup.md +153 -0
- package/plugin/workflows/microservices/service-scaffolding.md +151 -0
- package/plugin/workflows/omega/1000x-innovation.md +2 -2
- package/plugin/workflows/omega/100x-architecture.md +2 -2
- package/plugin/workflows/omega/10x-improvement.md +2 -2
- package/plugin/workflows/quality/performance-optimization.md +2 -2
- package/plugin/workflows/research/best-practices.md +1 -1
- package/plugin/workflows/research/technology-research.md +1 -1
- package/plugin/workflows/security/penetration-testing.md +3 -3
- package/plugin/workflows/security/security-audit.md +3 -3
- package/plugin/workflows/sprint/sprint-execution.md +2 -2
- package/plugin/workflows/sprint/sprint-retrospective.md +1 -1
- package/plugin/workflows/sprint/sprint-setup.md +1 -1
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
# Shader Programming
|
|
2
|
+
|
|
3
|
+
GPU shader development including HLSL/GLSL, vertex/fragment shaders, compute shaders, and visual effects.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Shader programming enables custom rendering effects, visual styles, and GPU-accelerated computations through programmable graphics pipeline stages.
|
|
8
|
+
|
|
9
|
+
## Core Concepts
|
|
10
|
+
|
|
11
|
+
### Shader Types
|
|
12
|
+
- **Vertex Shader**: Transform vertices
|
|
13
|
+
- **Fragment/Pixel Shader**: Calculate pixel colors
|
|
14
|
+
- **Geometry Shader**: Generate/modify primitives
|
|
15
|
+
- **Compute Shader**: General-purpose GPU computing
|
|
16
|
+
|
|
17
|
+
### Rendering Pipeline
|
|
18
|
+
```
|
|
19
|
+
Vertices → Vertex Shader → Rasterization → Fragment Shader → Output
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## HLSL Basics (Unity/DirectX)
|
|
23
|
+
|
|
24
|
+
### Simple Unlit Shader
|
|
25
|
+
```hlsl
|
|
26
|
+
Shader "Custom/SimpleUnlit"
|
|
27
|
+
{
|
|
28
|
+
Properties
|
|
29
|
+
{
|
|
30
|
+
_MainTex ("Texture", 2D) = "white" {}
|
|
31
|
+
_Color ("Color", Color) = (1,1,1,1)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
SubShader
|
|
35
|
+
{
|
|
36
|
+
Tags { "RenderType"="Opaque" }
|
|
37
|
+
LOD 100
|
|
38
|
+
|
|
39
|
+
Pass
|
|
40
|
+
{
|
|
41
|
+
CGPROGRAM
|
|
42
|
+
#pragma vertex vert
|
|
43
|
+
#pragma fragment frag
|
|
44
|
+
|
|
45
|
+
#include "UnityCG.cginc"
|
|
46
|
+
|
|
47
|
+
struct appdata
|
|
48
|
+
{
|
|
49
|
+
float4 vertex : POSITION;
|
|
50
|
+
float2 uv : TEXCOORD0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
struct v2f
|
|
54
|
+
{
|
|
55
|
+
float2 uv : TEXCOORD0;
|
|
56
|
+
float4 vertex : SV_POSITION;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
sampler2D _MainTex;
|
|
60
|
+
float4 _MainTex_ST;
|
|
61
|
+
float4 _Color;
|
|
62
|
+
|
|
63
|
+
v2f vert (appdata v)
|
|
64
|
+
{
|
|
65
|
+
v2f o;
|
|
66
|
+
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
67
|
+
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
|
68
|
+
return o;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fixed4 frag (v2f i) : SV_Target
|
|
72
|
+
{
|
|
73
|
+
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
|
|
74
|
+
return col;
|
|
75
|
+
}
|
|
76
|
+
ENDCG
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Lit Shader with Normal Mapping
|
|
83
|
+
```hlsl
|
|
84
|
+
Shader "Custom/NormalMapped"
|
|
85
|
+
{
|
|
86
|
+
Properties
|
|
87
|
+
{
|
|
88
|
+
_MainTex ("Albedo", 2D) = "white" {}
|
|
89
|
+
_BumpMap ("Normal Map", 2D) = "bump" {}
|
|
90
|
+
_BumpScale ("Normal Scale", Range(0, 2)) = 1.0
|
|
91
|
+
_Metallic ("Metallic", Range(0, 1)) = 0.0
|
|
92
|
+
_Smoothness ("Smoothness", Range(0, 1)) = 0.5
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
SubShader
|
|
96
|
+
{
|
|
97
|
+
Tags { "RenderType"="Opaque" }
|
|
98
|
+
|
|
99
|
+
CGPROGRAM
|
|
100
|
+
#pragma surface surf Standard fullforwardshadows
|
|
101
|
+
#pragma target 3.0
|
|
102
|
+
|
|
103
|
+
sampler2D _MainTex;
|
|
104
|
+
sampler2D _BumpMap;
|
|
105
|
+
half _BumpScale;
|
|
106
|
+
half _Metallic;
|
|
107
|
+
half _Smoothness;
|
|
108
|
+
|
|
109
|
+
struct Input
|
|
110
|
+
{
|
|
111
|
+
float2 uv_MainTex;
|
|
112
|
+
float2 uv_BumpMap;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
void surf (Input IN, inout SurfaceOutputStandard o)
|
|
116
|
+
{
|
|
117
|
+
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
|
|
118
|
+
o.Albedo = c.rgb;
|
|
119
|
+
|
|
120
|
+
o.Normal = UnpackScaleNormal(
|
|
121
|
+
tex2D(_BumpMap, IN.uv_BumpMap),
|
|
122
|
+
_BumpScale
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
o.Metallic = _Metallic;
|
|
126
|
+
o.Smoothness = _Smoothness;
|
|
127
|
+
o.Alpha = c.a;
|
|
128
|
+
}
|
|
129
|
+
ENDCG
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
FallBack "Diffuse"
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Visual Effects
|
|
137
|
+
|
|
138
|
+
### Dissolve Effect
|
|
139
|
+
```hlsl
|
|
140
|
+
Shader "Custom/Dissolve"
|
|
141
|
+
{
|
|
142
|
+
Properties
|
|
143
|
+
{
|
|
144
|
+
_MainTex ("Texture", 2D) = "white" {}
|
|
145
|
+
_NoiseTex ("Noise Texture", 2D) = "white" {}
|
|
146
|
+
_DissolveAmount ("Dissolve Amount", Range(0, 1)) = 0
|
|
147
|
+
_EdgeColor ("Edge Color", Color) = (1, 0.5, 0, 1)
|
|
148
|
+
_EdgeWidth ("Edge Width", Range(0, 0.2)) = 0.05
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
SubShader
|
|
152
|
+
{
|
|
153
|
+
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
|
|
154
|
+
Blend SrcAlpha OneMinusSrcAlpha
|
|
155
|
+
|
|
156
|
+
Pass
|
|
157
|
+
{
|
|
158
|
+
CGPROGRAM
|
|
159
|
+
#pragma vertex vert
|
|
160
|
+
#pragma fragment frag
|
|
161
|
+
|
|
162
|
+
#include "UnityCG.cginc"
|
|
163
|
+
|
|
164
|
+
struct appdata
|
|
165
|
+
{
|
|
166
|
+
float4 vertex : POSITION;
|
|
167
|
+
float2 uv : TEXCOORD0;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
struct v2f
|
|
171
|
+
{
|
|
172
|
+
float2 uv : TEXCOORD0;
|
|
173
|
+
float4 vertex : SV_POSITION;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
sampler2D _MainTex;
|
|
177
|
+
sampler2D _NoiseTex;
|
|
178
|
+
float _DissolveAmount;
|
|
179
|
+
float4 _EdgeColor;
|
|
180
|
+
float _EdgeWidth;
|
|
181
|
+
|
|
182
|
+
v2f vert (appdata v)
|
|
183
|
+
{
|
|
184
|
+
v2f o;
|
|
185
|
+
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
186
|
+
o.uv = v.uv;
|
|
187
|
+
return o;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
fixed4 frag (v2f i) : SV_Target
|
|
191
|
+
{
|
|
192
|
+
fixed4 col = tex2D(_MainTex, i.uv);
|
|
193
|
+
float noise = tex2D(_NoiseTex, i.uv).r;
|
|
194
|
+
|
|
195
|
+
// Dissolve threshold
|
|
196
|
+
float dissolve = noise - _DissolveAmount;
|
|
197
|
+
|
|
198
|
+
// Clip pixels below threshold
|
|
199
|
+
clip(dissolve);
|
|
200
|
+
|
|
201
|
+
// Edge glow
|
|
202
|
+
if (dissolve < _EdgeWidth)
|
|
203
|
+
{
|
|
204
|
+
float edgeBlend = dissolve / _EdgeWidth;
|
|
205
|
+
col.rgb = lerp(_EdgeColor.rgb, col.rgb, edgeBlend);
|
|
206
|
+
col.rgb += _EdgeColor.rgb * (1 - edgeBlend) * 2;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return col;
|
|
210
|
+
}
|
|
211
|
+
ENDCG
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Outline Shader
|
|
218
|
+
```hlsl
|
|
219
|
+
Shader "Custom/Outline"
|
|
220
|
+
{
|
|
221
|
+
Properties
|
|
222
|
+
{
|
|
223
|
+
_MainTex ("Texture", 2D) = "white" {}
|
|
224
|
+
_OutlineColor ("Outline Color", Color) = (0, 0, 0, 1)
|
|
225
|
+
_OutlineWidth ("Outline Width", Range(0, 0.1)) = 0.02
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
SubShader
|
|
229
|
+
{
|
|
230
|
+
Tags { "RenderType"="Opaque" }
|
|
231
|
+
|
|
232
|
+
// Outline pass
|
|
233
|
+
Pass
|
|
234
|
+
{
|
|
235
|
+
Cull Front
|
|
236
|
+
|
|
237
|
+
CGPROGRAM
|
|
238
|
+
#pragma vertex vert
|
|
239
|
+
#pragma fragment frag
|
|
240
|
+
|
|
241
|
+
#include "UnityCG.cginc"
|
|
242
|
+
|
|
243
|
+
float _OutlineWidth;
|
|
244
|
+
float4 _OutlineColor;
|
|
245
|
+
|
|
246
|
+
struct appdata
|
|
247
|
+
{
|
|
248
|
+
float4 vertex : POSITION;
|
|
249
|
+
float3 normal : NORMAL;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
struct v2f
|
|
253
|
+
{
|
|
254
|
+
float4 vertex : SV_POSITION;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
v2f vert (appdata v)
|
|
258
|
+
{
|
|
259
|
+
v2f o;
|
|
260
|
+
// Expand vertices along normals
|
|
261
|
+
float3 expandedPos = v.vertex.xyz + v.normal * _OutlineWidth;
|
|
262
|
+
o.vertex = UnityObjectToClipPos(float4(expandedPos, 1));
|
|
263
|
+
return o;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
fixed4 frag (v2f i) : SV_Target
|
|
267
|
+
{
|
|
268
|
+
return _OutlineColor;
|
|
269
|
+
}
|
|
270
|
+
ENDCG
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Regular pass
|
|
274
|
+
Pass
|
|
275
|
+
{
|
|
276
|
+
CGPROGRAM
|
|
277
|
+
#pragma vertex vert
|
|
278
|
+
#pragma fragment frag
|
|
279
|
+
|
|
280
|
+
#include "UnityCG.cginc"
|
|
281
|
+
|
|
282
|
+
sampler2D _MainTex;
|
|
283
|
+
|
|
284
|
+
struct appdata
|
|
285
|
+
{
|
|
286
|
+
float4 vertex : POSITION;
|
|
287
|
+
float2 uv : TEXCOORD0;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
struct v2f
|
|
291
|
+
{
|
|
292
|
+
float2 uv : TEXCOORD0;
|
|
293
|
+
float4 vertex : SV_POSITION;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
v2f vert (appdata v)
|
|
297
|
+
{
|
|
298
|
+
v2f o;
|
|
299
|
+
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
300
|
+
o.uv = v.uv;
|
|
301
|
+
return o;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
fixed4 frag (v2f i) : SV_Target
|
|
305
|
+
{
|
|
306
|
+
return tex2D(_MainTex, i.uv);
|
|
307
|
+
}
|
|
308
|
+
ENDCG
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## GLSL (WebGL/OpenGL)
|
|
315
|
+
|
|
316
|
+
### Basic Fragment Shader
|
|
317
|
+
```glsl
|
|
318
|
+
#version 300 es
|
|
319
|
+
precision highp float;
|
|
320
|
+
|
|
321
|
+
uniform sampler2D uTexture;
|
|
322
|
+
uniform float uTime;
|
|
323
|
+
uniform vec2 uResolution;
|
|
324
|
+
|
|
325
|
+
in vec2 vUv;
|
|
326
|
+
out vec4 fragColor;
|
|
327
|
+
|
|
328
|
+
void main() {
|
|
329
|
+
vec2 uv = vUv;
|
|
330
|
+
|
|
331
|
+
// Animated wave distortion
|
|
332
|
+
uv.x += sin(uv.y * 10.0 + uTime) * 0.02;
|
|
333
|
+
uv.y += cos(uv.x * 10.0 + uTime) * 0.02;
|
|
334
|
+
|
|
335
|
+
vec4 color = texture(uTexture, uv);
|
|
336
|
+
fragColor = color;
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Post-Processing Effect
|
|
341
|
+
```glsl
|
|
342
|
+
#version 300 es
|
|
343
|
+
precision highp float;
|
|
344
|
+
|
|
345
|
+
uniform sampler2D uSceneTexture;
|
|
346
|
+
uniform float uVignetteStrength;
|
|
347
|
+
uniform float uSaturation;
|
|
348
|
+
uniform vec3 uColorGrade;
|
|
349
|
+
|
|
350
|
+
in vec2 vUv;
|
|
351
|
+
out vec4 fragColor;
|
|
352
|
+
|
|
353
|
+
vec3 adjustSaturation(vec3 color, float saturation) {
|
|
354
|
+
vec3 grey = vec3(dot(color, vec3(0.299, 0.587, 0.114)));
|
|
355
|
+
return mix(grey, color, saturation);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
float vignette(vec2 uv, float strength) {
|
|
359
|
+
vec2 center = uv - 0.5;
|
|
360
|
+
float dist = length(center);
|
|
361
|
+
return 1.0 - smoothstep(0.3, 0.7, dist * strength);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
void main() {
|
|
365
|
+
vec4 scene = texture(uSceneTexture, vUv);
|
|
366
|
+
|
|
367
|
+
// Apply saturation
|
|
368
|
+
vec3 color = adjustSaturation(scene.rgb, uSaturation);
|
|
369
|
+
|
|
370
|
+
// Apply color grading
|
|
371
|
+
color *= uColorGrade;
|
|
372
|
+
|
|
373
|
+
// Apply vignette
|
|
374
|
+
float vig = vignette(vUv, uVignetteStrength);
|
|
375
|
+
color *= vig;
|
|
376
|
+
|
|
377
|
+
fragColor = vec4(color, scene.a);
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Compute Shaders
|
|
382
|
+
|
|
383
|
+
### Particle Simulation
|
|
384
|
+
```hlsl
|
|
385
|
+
#pragma kernel UpdateParticles
|
|
386
|
+
|
|
387
|
+
struct Particle
|
|
388
|
+
{
|
|
389
|
+
float3 position;
|
|
390
|
+
float3 velocity;
|
|
391
|
+
float life;
|
|
392
|
+
float size;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
RWStructuredBuffer<Particle> particles;
|
|
396
|
+
float deltaTime;
|
|
397
|
+
float3 gravity;
|
|
398
|
+
int particleCount;
|
|
399
|
+
|
|
400
|
+
[numthreads(256, 1, 1)]
|
|
401
|
+
void UpdateParticles(uint3 id : SV_DispatchThreadID)
|
|
402
|
+
{
|
|
403
|
+
if (id.x >= (uint)particleCount) return;
|
|
404
|
+
|
|
405
|
+
Particle p = particles[id.x];
|
|
406
|
+
|
|
407
|
+
// Update physics
|
|
408
|
+
p.velocity += gravity * deltaTime;
|
|
409
|
+
p.position += p.velocity * deltaTime;
|
|
410
|
+
|
|
411
|
+
// Update life
|
|
412
|
+
p.life -= deltaTime;
|
|
413
|
+
|
|
414
|
+
// Respawn if dead
|
|
415
|
+
if (p.life <= 0)
|
|
416
|
+
{
|
|
417
|
+
p.position = float3(0, 0, 0);
|
|
418
|
+
p.velocity = float3(
|
|
419
|
+
(frac(sin(id.x * 12.9898) * 43758.5453) - 0.5) * 2,
|
|
420
|
+
frac(sin(id.x * 78.233) * 43758.5453) * 5 + 2,
|
|
421
|
+
(frac(sin(id.x * 45.164) * 43758.5453) - 0.5) * 2
|
|
422
|
+
);
|
|
423
|
+
p.life = 3.0;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
particles[id.x] = p;
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
## Unity Shader Graph
|
|
431
|
+
|
|
432
|
+
### Custom Function Node
|
|
433
|
+
```hlsl
|
|
434
|
+
// Custom function for Shader Graph
|
|
435
|
+
void Fresnel_float(
|
|
436
|
+
float3 Normal,
|
|
437
|
+
float3 ViewDir,
|
|
438
|
+
float Power,
|
|
439
|
+
out float Out)
|
|
440
|
+
{
|
|
441
|
+
Out = pow(1.0 - saturate(dot(Normal, ViewDir)), Power);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
void Triplanar_float(
|
|
445
|
+
Texture2D Tex,
|
|
446
|
+
SamplerState SS,
|
|
447
|
+
float3 Position,
|
|
448
|
+
float3 Normal,
|
|
449
|
+
float Blend,
|
|
450
|
+
out float4 Out)
|
|
451
|
+
{
|
|
452
|
+
float3 bf = pow(abs(Normal), Blend);
|
|
453
|
+
bf /= dot(bf, 1.0);
|
|
454
|
+
|
|
455
|
+
float4 xAxis = SAMPLE_TEXTURE2D(Tex, SS, Position.yz);
|
|
456
|
+
float4 yAxis = SAMPLE_TEXTURE2D(Tex, SS, Position.xz);
|
|
457
|
+
float4 zAxis = SAMPLE_TEXTURE2D(Tex, SS, Position.xy);
|
|
458
|
+
|
|
459
|
+
Out = xAxis * bf.x + yAxis * bf.y + zAxis * bf.z;
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Best Practices
|
|
464
|
+
|
|
465
|
+
1. **Minimize Branching**: GPUs prefer uniform execution
|
|
466
|
+
2. **Batch Draw Calls**: Combine similar materials
|
|
467
|
+
3. **LOD Shaders**: Simpler shaders for distant objects
|
|
468
|
+
4. **Profile GPU**: Use tools like RenderDoc
|
|
469
|
+
5. **Fallbacks**: Provide simpler shader alternatives
|
|
470
|
+
|
|
471
|
+
## Anti-Patterns
|
|
472
|
+
|
|
473
|
+
- Complex math in fragment shader
|
|
474
|
+
- Too many texture samples
|
|
475
|
+
- Dynamic branching in loops
|
|
476
|
+
- Ignoring precision (mobile)
|
|
477
|
+
- No shader variants
|
|
478
|
+
|
|
479
|
+
## When to Use
|
|
480
|
+
|
|
481
|
+
- Custom visual styles
|
|
482
|
+
- Performance-critical effects
|
|
483
|
+
- GPU-accelerated computation
|
|
484
|
+
- Unique rendering techniques
|
|
485
|
+
- VFX and post-processing
|
|
486
|
+
|
|
487
|
+
## When NOT to Use
|
|
488
|
+
|
|
489
|
+
- Standard rendering suffices
|
|
490
|
+
- Prototyping phase
|
|
491
|
+
- No GPU expertise on team
|
|
492
|
+
- Target hardware too weak
|