Skip to content

Commit 5a0789b

Browse files
committed
More shader stuff. Updated export templates and README.
1 parent c1d4ef7 commit 5a0789b

File tree

6 files changed

+120
-14
lines changed

6 files changed

+120
-14
lines changed

exportTemplates/defaultLuaClipboard.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ for _, ps in ipairs(particleSystems) do
7575
Text"-- ps:emit(" LuaCsv(ps.emitAtStart) Text")\n"
7676
end
7777
end
78+
7879
Text"-- At draw time:\n"
80+
if ps.shaderFilename ~= "" then
81+
Text"-- love.graphics.setShader(?) -- " Text(ps.shaderPath ~= "" and ps.shaderPath or ps.shaderFilename) Text"\n"
82+
end
7983
Text"-- love.graphics.setBlendMode(" LuaCsv(ps.blendMode) Text")\n"
8084
Text"-- love.graphics.draw(ps)\n"
8185
end

exportTemplates/defaultLuaModule.lua

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
Text [=[
22
--[[
33
module = {
4-
{ system=particleSystem1, kickStartSteps=steps1, kickStartDt=dt1, emitAtStart=count1, blendMode=blendMode1 },
5-
{ system=particleSystem2, kickStartSteps=steps2, kickStartDt=dt2, emitAtStart=count2, blendMode=blendMode2 },
4+
{
5+
system=particleSystem1,
6+
kickStartSteps=steps1, kickStartDt=dt1, emitAtStart=count1,
7+
blendMode=blendMode1, shader=shader1,
8+
texturePreset=preset1, texturePath=path1,
9+
shaderPath=path1, shaderFilename=filename1
10+
},
11+
{ system=particleSystem2, ... },
612
...
713
}
814
]]
@@ -43,6 +49,39 @@ for _, ps in ipairs(particleSystems) do
4349
imageIdentBySystem[ps] = imageIdent
4450
end
4551

52+
-- Define shaders. Some may be shared between multiple particle systems.
53+
local shaderIdentBySystem = {}
54+
local shaderIdentByPath = {}
55+
local shaderIdentByFilename = {}
56+
local shaderN = 0
57+
58+
for _, ps in ipairs(particleSystems) do
59+
if ps.shaderFilename ~= "" then
60+
local shaderIdentByKey = ps.shaderPath ~= "" and shaderIdentByPath or shaderIdentByFilename
61+
local key = ps.shaderPath ~= "" and ps.shaderPath or ps.shaderFilename
62+
local shaderIdent = shaderIdentByKey[key]
63+
64+
if not shaderIdent then
65+
shaderN = shaderN + 1
66+
shaderIdent = "shader" .. shaderN
67+
shaderIdentByKey[key] = shaderIdent
68+
69+
if shaderN == 1 then Text"\n" end
70+
71+
if ps.shaderPath == "" then
72+
Text"local " Text(shaderIdent) Text" = ? -- Filename: " Text(ps.shaderFilename) Text"\n"
73+
else
74+
Text"local " Text(shaderIdent) Text" = LG.newShader(" LuaCsv(ps.shaderPath) Text")\n"
75+
end
76+
end
77+
78+
shaderIdentBySystem[ps] = shaderIdent
79+
80+
else
81+
shaderIdentBySystem[ps] = "nil"
82+
end
83+
end
84+
4685
-- Define particle systems.
4786
for _, ps in ipairs(particleSystems) do
4887
Text"\n"
@@ -83,6 +122,11 @@ for _, ps in ipairs(particleSystems) do
83122
Text", kickStartDt=" LuaCsv(ps.kickStartDt)
84123
Text", emitAtStart=" LuaCsv(ps.emitAtStart)
85124
Text", blendMode=" LuaCsv(ps.blendMode)
125+
Text", shader=" Text(shaderIdentBySystem[ps])
126+
Text", texturePath=" LuaCsv(ps.texturePath)
127+
Text", texturePreset=" LuaCsv(ps.texturePreset)
128+
Text", shaderPath=" LuaCsv(ps.shaderPath)
129+
Text", shaderFilename=" LuaCsv(ps.shaderFilename)
86130
Text"})\n"
87131
end
88132

misc/README.txt

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ Developed by Marcus 'ReFreezed' Thunström
66
3. Controls
77
4. Shortcuts
88
5. Parameters
9-
6. Exporting
10-
7. Template API
9+
6. Custom shaders
10+
7. Exporting
11+
8. Template API
1112

1213

1314

@@ -106,13 +107,17 @@ Ctrl+Shift+Z Redo
106107
Project settings
107108
------------------------------------------------------------------------------
108109

110+
Custom data: A custom data string attached to the project that can be used by
111+
an export script.
112+
109113
Pixelate:
110114
- World: Enable pixel art mode. Zoom in on the particles to see the effect.
111115
- Textures: Enable nearest neighbor filtering on textures. Linear filtering is
112116
used by default.
113117

114118
Background: Change the background of the particle viewing area.
115119
- Pattern: Change the opacity of the checker pattern in the background.
120+
- Size: Change the size of the pattern.
116121

117122
Emitter movement: Automatically move the emitter in a pattern.
118123
- Scale: Specify how much the emitter should move. Set one axis to 0% to use
@@ -126,6 +131,9 @@ Global scale: Scale time, space and/or size parameters for all particle
126131
Particle system parameters
127132
------------------------------------------------------------------------------
128133

134+
Custom data: A custom data string attached to the particle system that can be
135+
used by an export script.
136+
129137
Texture: Choose a built-in texture preset or specify a path to an image file.
130138
- Offset: Choose where the anchor point of the texture should be for each
131139
particle. The anchor point is the point the particle rotates around, among
@@ -187,6 +195,8 @@ Color: The color of particles. You can specify up to 8 colors to animate the
187195
over time on the right hand side.
188196
- Blend mode: The blend mode for the particle system.
189197

198+
Shader: Path to a shader file to be used when rendering the particles.
199+
190200

191201
Animation dialog
192202
------------------------------------------------------------------------------
@@ -207,7 +217,26 @@ Sequence: Tool used for quickly generating quads based on a rectangular area
207217

208218

209219

210-
6. Exporting
220+
6. Custom shaders
221+
==============================================================================
222+
223+
You can specify what shaders should be used when rendering particle systems.
224+
The program exposes some values that can be used in the shaders:
225+
226+
HOT_PARTICLES
227+
This is defined for the preprocessor and can be used with #ifdef or in
228+
defined().
229+
230+
hotParticlesTime
231+
Uniform float. Contains the current time.
232+
233+
hotParticlesEmitterTime
234+
Uniform float. Contains the current emitter time (i.e it resets along
235+
with the emitter).
236+
237+
238+
239+
7. Exporting
211240
==============================================================================
212241

213242
It's possible to export particle system information and textures (the original
@@ -222,7 +251,7 @@ edit existing scripts or make completely new ones to fit your game (see the
222251

223252

224253

225-
7. Template API
254+
8. Template API
226255
==============================================================================
227256

228257
Templates are normal Lua scripts in the "exportTemplates" folder. Some of the
@@ -275,6 +304,8 @@ Values:
275304
radialAcceleration table Table with these numeric fields: min, max. Is also an array.
276305
relativeRotation boolean True if relative rotation is enabled, false otherwise
277306
rotation table Table with these numeric fields: min, max. Is also an array.
307+
shaderFilename string Filename of the shader. Is empty if no shader has been specified. This could be used as a fallback for when shaderPath is empty.
308+
shaderPath string Path to the shader relative to the specified base folder. Is empty if no shader has been specified or no path is available.
278309
sizes table Sequence of sizes.
279310
sizeVariation number How varied the sizes are. The value is between 0 and 1.
280311
speed table Table with these numeric fields: min, max. Is also an array.

src/gui.gloa

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ local positionAndFit :: (state:State, el:Element, x,y,w,h:int) {
16491649

16501650
case InputText:
16511651
local input = cast(InputText) el
1652-
if input.field ~= NULL input.field.setWidth!(w)
1652+
if input.field ~= NULL input.field.setWidth!(w - 2*SPACING)
16531653
}
16541654
}
16551655

@@ -2976,6 +2976,7 @@ export setFocus :: (state:State, input:InputText) {
29762976
}
29772977

29782978
input.field.setText!(input.value)
2979+
input.field.setScroll!(0)
29792980
}
29802981

29812982
export blurFocus :: (state:State, abort=false) {

src/guiSetup.gloa

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export setupGuiFrames :: () {
3030
guiState.separator!({ thick=true }),
3131

3232
guiState.vbox!({ name="projectSettings",
33-
guiState.section!({ label="Custom data",
33+
guiState.section!({ --[[name="customDataProjectSection",]] label="Custom data",
3434
guiState.inputText!({ name="customDataProject" }),
3535
}),
3636

@@ -91,7 +91,7 @@ export setupGuiFrames :: () {
9191
guiState.tabs!({ name="systems", specialLastTab=true }),
9292

9393
guiState.scrollable!({
94-
guiState.section!({ label="Custom data",
94+
guiState.section!({ --[[name="customDataSystemSection",]] label="Custom data",
9595
guiState.inputText!({ name="customDataSystem" }),
9696
}),
9797

@@ -2717,7 +2717,7 @@ export setupGuiCallbacks :: () {
27172717
local ^ok, basePath = resolveBaseOuputPath(project)
27182718
if ok {
27192719
local ^ok, texturePathObj = Path.getRelativeTo(texturePath, basePath)
2720-
if ok texturePath = texturePathObj.toString!()
2720+
if ok and texturePathObj.path[1] ~= ".." texturePath = texturePathObj.toString!()
27212721
}
27222722
} else {
27232723
texturePath = ""
@@ -2726,23 +2726,45 @@ export setupGuiCallbacks :: () {
27262726
publicParticleSystem.texturePath = texturePath
27272727
}
27282728

2729+
do {
2730+
local shaderPath = ""
2731+
local shaderFilename = ""
2732+
2733+
local ^ok, shaderPathFull = getShaderFullPath(project, system)
2734+
if ok {
2735+
ok, shaderFilename = Path(system.shaderPath).getFilename!()
2736+
if not ok shaderFilename = ""
2737+
2738+
shaderPath = shaderFilename
2739+
2740+
local ^ok, basePath = resolveBaseOuputPath(project)
2741+
if ok {
2742+
local ^ok, shaderPathObj = Path.getRelativeTo(shaderPathFull, basePath)
2743+
if ok and shaderPathObj.path[1] ~= ".." shaderPath = shaderPathObj.toString!()
2744+
}
2745+
}
2746+
2747+
publicParticleSystem.shaderPath = shaderPath
2748+
publicParticleSystem.shaderFilename = shaderFilename
2749+
}
2750+
27292751
publicParticleSystem.blendMode = system.blendMode
27302752
publicParticleSystem.bufferSize = getOptimalBufferSize(system)
2753+
publicParticleSystem.customData = system.customData
27312754
publicParticleSystem.direction = ps.getDirection!()
27322755
publicParticleSystem.emissionRate = ps.getEmissionRate!()
27332756
publicParticleSystem.emitAtStart = system.kickStartEmit
27342757
publicParticleSystem.emitterLifetime = ps.getEmitterLifetime!()
27352758
publicParticleSystem.insertMode = ps.getInsertMode!()
2736-
publicParticleSystem.kickStartSteps = system.kickStartSteps
27372759
publicParticleSystem.kickStartDt = getKickStartDt(system)
2760+
publicParticleSystem.kickStartSteps = system.kickStartSteps
27382761
publicParticleSystem.relativeRotation = ps.hasRelativeRotation!()
27392762
publicParticleSystem.sizes = cast([]float) { ps.getSizesAsVararg!() }
27402763
publicParticleSystem.sizeVariation = ps.getSizeVariation!()
27412764
publicParticleSystem.spinVariation = ps.getSpinVariation!()
27422765
publicParticleSystem.spread = ps.getSpread!()
27432766
publicParticleSystem.texturePreset = system.textureName
27442767
publicParticleSystem.title = system.title
2745-
publicParticleSystem.customData = system.customData
27462768

27472769
do { local min,max = ps.getLinearDamping!() ; publicParticleSystem.linearDamping = cast(table) {min,max, min=min,max=max} }
27482770
do { local min,max = ps.getParticleLifetime!() ; publicParticleSystem.particleLifetime = cast(table) {min,max, min=min,max=max} }

src/main.gloa

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ local zoomTime = -9999.00
131131

132132
local updateId = 0
133133

134-
local timeForAnimationPreview = 0.00
134+
local timeForAnimationPreview = 0.00
135+
local particleEmitDurationTotal = 0.00
135136

136137
export isMac: bool
137138
export lctrl: LK.KeyConstant
@@ -652,6 +653,7 @@ export updateParticleShader :: (project:Project, system:System, saveRecent=false
652653
versionLine.."\z
653654
#define HOT_PARTICLES\n\z
654655
uniform float hotParticlesTime;\n\z
656+
uniform float hotParticlesEmitterTime;\n\z
655657
"..shaderCode
656658

657659
local shader, err = pcall_newShader(shaderCode)
@@ -1353,6 +1355,7 @@ local onUpdate :: (dt:float) {
13531355
particleUpdateTime = LT.getTime()-time
13541356

13551357
project.particleEmitDuration += dtForParticles
1358+
particleEmitDurationTotal += dtForParticles
13561359

13571360
for 2, particleUpdateCount {
13581361
project.particleEmitDuration += dtForParticles
@@ -1567,7 +1570,8 @@ local onDraw :: () {
15671570
for system: project.systems if system.visible {
15681571
local shader = system.currentShader
15691572
if shader ~= NULL {
1570-
if shader.hasUniform!"hotParticlesTime" shader.send!("hotParticlesTime", project.particleEmitDuration)
1573+
if shader.hasUniform!"hotParticlesTime" shader.send!("hotParticlesTime", particleEmitDurationTotal)
1574+
if shader.hasUniform!"hotParticlesEmitterTime" shader.send!("hotParticlesEmitterTime", project.particleEmitDuration)
15711575
}
15721576
LG.setShader(shader)
15731577
LG.setBlendMode(system.blendMode)

0 commit comments

Comments
 (0)