Browse Source

Added implementation of generic "run particle effect", which is used for things like blood effects and bullet wall impacts. Also tweaked the setup of particle rendering to be more in line with QuakeSpasm, though I'll need to do a good A/B comparison sometime.

readme
Nico de Poel 5 years ago
parent
commit
5e607f4239
  1. 9
      Assets/Scripts/Data/QExtensions.cs
  2. 13
      Assets/Scripts/Modules/GameModule.Interop.cs
  3. 5
      Assets/Scripts/Modules/GameModule.cs
  4. 35
      Assets/Scripts/VisualStyle.cs
  5. 2
      Assets/Styles/GLQuake/GLQuake.asset
  6. 6
      Assets/Styles/GLQuake/Particles/Particle.mat
  7. 4864
      Assets/Styles/GLQuake/Particles/ParticleEffect.prefab
  8. 7
      Assets/Styles/GLQuake/Particles/ParticleEffect.prefab.meta
  9. 5
      engine/Quake/r_part.c
  10. 1
      engine/Quake/render.h
  11. 10
      engine/UniQuake/game_uniquake.c

9
Assets/Scripts/Data/QExtensions.cs

@ -62,4 +62,13 @@ public static class QExtensions
* Quaternion.AngleAxis(angles.x, Vector3.right)
* Quaternion.AngleAxis(angles.z, Vector3.forward);
}
public static Color ToColor(this uint color)
{
return new Color32(
(byte)(color & 0xFF),
(byte)((color >> 8) & 0xFF),
(byte)((color >> 16) & 0xFF),
(byte)((color >> 24) & 0xFF));
}
}

13
Assets/Scripts/Modules/GameModule.Interop.cs

@ -18,6 +18,7 @@ public partial class GameModule : CallbackHandler<GameModule>
UpdateEntityAnimation = CreateCallback<GameUpdateEntityAnimationCallback>(Callback_GameUpdateEntityAnimation),
SetEntitySkin = CreateCallback<GameSetEntitySkinCallback>(Callback_GameSetEntitySkin),
RunParticleEffect = CreateCallback<RunParticleEffectCallback>(Callback_RunParticleEffect),
ParticleExplosion = CreateCallback<ParticleExplosionCallback>(Callback_ParticleExplosion),
};
@ -36,6 +37,7 @@ public partial class GameModule : CallbackHandler<GameModule>
public IntPtr UpdateEntityAnimation;
public IntPtr SetEntitySkin;
public IntPtr RunParticleEffect;
public IntPtr ParticleExplosion;
}
@ -94,6 +96,17 @@ public partial class GameModule : CallbackHandler<GameModule>
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void RunParticleEffectCallback(IntPtr context, ref QVec3 origin, ref QVec3 direction, uint colorMin, uint colorMax, int count);
[MonoPInvokeCallback(typeof(RunParticleEffectCallback))]
private static void Callback_RunParticleEffect(IntPtr context, ref QVec3 origin, ref QVec3 direction, uint colorMin, uint colorMax, int count)
{
Profiler.BeginSample("RunParticleEffect");
GetSelf(context).RunParticleEffect(origin.ToUnityPosition(), direction.ToUnityPosition(), colorMin.ToColor(), colorMax.ToColor(), count);
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void ParticleExplosionCallback(IntPtr context, ref QVec3 origin);

5
Assets/Scripts/Modules/GameModule.cs

@ -68,6 +68,11 @@ public partial class GameModule
uq.GameState.GetEntity(entityNum).SetSkin(skinNum);
}
private void RunParticleEffect(Vector3 position, Vector3 direction, Color colorMin, Color colorMax, int count)
{
uq.CurrentStyle.Particles.RunParticleEffect(position, direction, colorMin,colorMax, count, uq.GameLayer);
}
private void ParticleExplosion(Vector3 position)
{
uq.CurrentStyle.Particles.CreateExplosion(position, uq.GameLayer);

35
Assets/Scripts/VisualStyle.cs

@ -152,17 +152,46 @@ public class LiquidProperties
[System.Serializable]
public class ParticleSystems
{
[SerializeField]
protected ParticleSystem particleEffect;
[SerializeField]
protected ParticleSystem explosion;
public virtual void RunParticleEffect(Vector3 position, Vector3 direction, Color colorMin, Color colorMax, int count, Layers layer)
{
if (particleEffect == null)
return;
var effect = Object.Instantiate(particleEffect);
SetLayer(effect.gameObject, layer);
effect.transform.position = position;
var main = effect.main;
main.maxParticles = count;
var startColor = main.startColor;
startColor.gradient.colorKeys = new[]
{
new GradientColorKey(colorMin, 0f),
new GradientColorKey(colorMax, 1f),
};
main.startColor = startColor;
var velocity = effect.velocityOverLifetime;
velocity.x = direction.x * 15f;
velocity.y = direction.y * 15f;
velocity.z = direction.z * 15f;
}
public virtual void CreateExplosion(Vector3 position, Layers layer)
{
if (explosion == null)
return;
var go = Object.Instantiate(explosion.gameObject);
go.transform.position = position;
SetLayer(go, layer);
var effect = Object.Instantiate(explosion);
SetLayer(effect.gameObject, layer);
effect.transform.position = position;
}
protected static void SetLayer(GameObject go, Layers layer)

2
Assets/Styles/GLQuake/GLQuake.asset

@ -23,5 +23,7 @@ MonoBehaviour:
lavaAlpha: 0.9
teleAlpha: 1
particles:
particleEffect: {fileID: 9150008102338277659, guid: d911d6d226122ae4e97a2fc6f268503d,
type: 3}
explosion: {fileID: 9150008102338277659, guid: 94e2cf23692eef24d9a5145b0f705c55,
type: 3}

6
Assets/Styles/GLQuake/Particles/Particle.mat

@ -22,7 +22,7 @@ Material:
m_PrefabAsset: {fileID: 0}
m_Name: Particle
m_Shader: {fileID: 4800000, guid: 0406db5a14f94604a8c57ccfbc9f3b46, type: 3}
m_ShaderKeywords: _COLORCOLOR_ON
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
@ -100,7 +100,7 @@ Material:
- _CameraNearFadeDistance: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _ColorMode: 4
- _ColorMode: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
@ -134,7 +134,7 @@ Material:
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _BaseColorAddSubDiff: {r: -1, g: 0, b: 0, a: 0}
- _BaseColorAddSubDiff: {r: 1, g: 0, b: 0, a: 0}
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

4864
Assets/Styles/GLQuake/Particles/ParticleEffect.prefab
File diff suppressed because it is too large
View File

7
Assets/Styles/GLQuake/Particles/ParticleEffect.prefab.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d911d6d226122ae4e97a2fc6f268503d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

5
engine/Quake/r_part.c

@ -521,6 +521,11 @@ void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
}
}
}
if (count == 1024)
UQ_Game_ParticleExplosion(org);
else
UQ_Game_RunParticleEffect(org, dir, color, count);
}
/*

1
engine/Quake/render.h

@ -178,6 +178,7 @@ void R_SetVrect (vrect_t *pvrect, vrect_t *pvrectin, int lineadj);
typedef struct mleaf_s mleaf_t;
void UQ_GL_SetupView(vec3_t origin, vec3_t angles, mleaf_t *viewLeaf);
void UQ_Game_RunParticleEffect(vec3_t origin, vec3_t direction, int color, int count);
void UQ_Game_ParticleExplosion(vec3_t origin);
#endif /* _QUAKE_RENDER_H */

10
engine/UniQuake/game_uniquake.c

@ -9,6 +9,8 @@ typedef struct unity_gamecalls_s
void(*RemoveEntity)(void *context, int entityNum);
void(*UpdateEntityAnimation)(void *context, int entityNum, int pose1, int pose2, float blend);
void(*SetEntitySkin)(void *context, int entityNum, int skinNum);
void(*RunParticleEffect)(void *context, vec3_t origin, vec3_t direction, unsigned int colorMin, unsigned int colorMax, int count);
void(*ParticleExplosion)(void *context, vec3_t origin);
} unity_gamecalls_t;
@ -46,6 +48,14 @@ void UQ_Game_SetEntitySkin(int entityNum, int skinNum)
unity_gamecalls->SetEntitySkin(unity_context, entityNum, skinNum);
}
void UQ_Game_RunParticleEffect(vec3_t origin, vec3_t direction, int color, int count)
{
unsigned int colorMin, colorMax;
colorMin = d_8to24table[color & ~7];
colorMax = d_8to24table[color | 7];
unity_gamecalls->RunParticleEffect(unity_context, origin, direction, colorMin, colorMax, count);
}
void UQ_Game_ParticleExplosion(vec3_t origin)
{
unity_gamecalls->ParticleExplosion(unity_context, origin);

Loading…
Cancel
Save