- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我希望你能听懂我的英语。
我使用源代码手动将相机的投影更改为正交投影。请引用下面的代码。
using UnityEngine;
using System.Collections;
public class CameraOrthoController : MonoBehaviour
{
private Matrix4x4 ortho;
private Matrix4x4 perspective;
public float near = 0.001f;
public float far = 1000f;
private float aspect;
public static CameraOrthoController Instance
{
get
{
return instance;
}
set { }
}
//-----------------------------------------------------
private static CameraOrthoController instance = null;
//---------------------------------------------------
// Use this for initialization
void Awake()
{
if (instance)
{
DestroyImmediate(gameObject);
return;
}
// 이 인스턴스를 유효한 유일 오브젝트로 만든다
instance = this;
}
private void Start()
{
perspective = Camera.main.projectionMatrix;
}
public void StartMatrixBlender(float OrthoSize)
{
aspect = (Screen.width + 0.0f) / (Screen.height + 0.0f);
if (OrthoSize != 0f)
{
float vertical = OrthoSize;
float horizontal = (vertical * 16f) / 9f;
ortho = Matrix4x4.Ortho(-horizontal, horizontal, -vertical, vertical, near, far);
BlendToMatrix(ortho, 1f);
}
else
{
BlendToMatrix(perspective, 1f);
}
}
//---------------------------------------
private Matrix4x4 MatrixLerp(Matrix4x4 from, Matrix4x4 to, float time)
{
Matrix4x4 ret = new Matrix4x4();
int i;
for (i = 0; i < 16; i++)
ret[i] = Mathf.Lerp(from[i], to[i], time);
return ret;
}
IEnumerator LerpFromTo(Matrix4x4 src, Matrix4x4 dest, float duration)
{
float startTime = Time.time;
while (Time.time - startTime < duration)
{
Camera.main.projectionMatrix = MatrixLerp(src, dest, (Time.time - startTime) / duration);
yield return new WaitForSeconds(0f);
}
Camera.main.projectionMatrix = dest;
}
//-------------------------------------------------
private Coroutine BlendToMatrix(Matrix4x4 targetMatrix, float duration)
{
StopAllCoroutines();
return StartCoroutine(LerpFromTo(Camera.main.projectionMatrix, targetMatrix, duration));
}
//-------------------------------------------------
public void OnEvent(EVENT_TYPE Event_Type, Component Sender, object Param = null, object Param2 = null)
{
switch (Event_Type)
{
}
}
}
我就是这样使用代码的。
CameraOrthoController.Instance.StartMatrixBlender(OrthographicSize);
目前为止效果很好。但是,当我为效果添加粒子系统时出现了问题。
The screen where the problem is occurring
在正常状态下,效果出现在游戏对象的前面,如上图底部的场景屏幕所示。
但是如果我用我上面写的代码来操作camera,效果总是会被所有gameobject遮挡,就好像在游戏画面的最上方一样。尽管效果位于游戏对象的前面。
起初,我认为可以通过图层排序来解决它,但我认为这不是图层问题,因为它在正常相机条件下是可见的。
我想知道上面代码的问题在哪里,因为我必须使用它们。
如果您知道如何解决,请告诉我。谢谢。
最佳答案
当您修改 Camera.projectionMatrix
时,相机将不再根据视野更新其渲染。粒子将保留在 GameObject 后面,直到您调用 Camera.ResetProjectionMatrix()
这结束了设置 Camera.projectionMatrix
属性的效果。
如果这不起作用,请使用多个摄像机使粒子系统始终出现在 3D 对象的顶部。基本上,您使用主相机渲染 3D 对象和其他对象,然后使用另一个相机渲染粒子系统。
图层:
1.新建图层并命名为“Particle”
2.将Particle System层更改为Particle
主摄像头:
1.确保主相机的Clear Flags
设置为Skybox
。
2。将Culling Mask
更改为“Everything”。单击 Everything
,这是 Culling Mask
的设置,然后取消选择/取消选中 Particle
。
3。确保其深度
设置为0
。
相机此时不应渲染粒子系统。
新相机:
1.创建新相机。确保它与主摄像头处于相同的位置/旋转。同时删除附加到它的 AudioListener
。
2。将 Clear Flags
更改为 Depth only
。
3.将相机的Culling Mask
更改为Particle
,并确保“Culling Mask”中没有选择任何其他内容
4。将深度更改为 1
。
这将使粒子系统始终显示在使用第一个或主相机渲染的每个对象的顶部。
如果您希望粒子系统出现在 Sprite/2d 对象而不是 Mesh/3D 对象之上,请将粒子的 Renderer
的 sortingOrder
更改为更大比 SpriteRenderer 的 sortingOrder
。默认值为 0,因此将 Particle 的 sortingOrder 更改为 1 或 2 应该没问题。
particle.GetComponent<Renderer>().sortingOrder = 2;
关于c# - 另一个游戏对象背后的粒子系统渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50254797/
我正在创建一个使用 tsParticles 的 Preact 组件库,但什么也没有出现。 我正在移植 React project但可能有些地方不兼容。 您可以在此处 checkout 组件:https
我试图为具有三的粒子提供速度和原点,但我无法添加原点 function getOrigin() { return new THREE.Vector3(Weapon.vehicle.posit
当用户单击任何粒子时,我希望它扩展和淡出,并且在与任何其他粒子碰撞时,该粒子也会扩展和淡出。现在我的问题是我想知道是否有一种方法可以让这些粒子(在本例中由构造函数制成)在碰撞时相互影响。链接至Code
http://www.mrspeaker.net/ 这个人制作了他的整个背景粒子,但我一直在 Inspect Element 中漫游以弄清楚他是怎么做到的,又不能。我不太确定它是如何完成的,有人知道他
这是我个人网站的存储库:https://github.com/flakpanzer40/flakpanzer40.github.io 您可能会注意到,我使用的粒子只是显示在我的名字、图片和描述下方。我
我在实现粒子 JS 时遇到了问题。我添加了两个 JS 文件,但在浏览器中没有得到任何输出。这是我的代码。 particles.js 最佳答案 您的 b
我正在尝试将粒子 js 设置为我网站的背景。我正在尝试应用这个: https://codepen.io/nikspatel/pen/aJGqpv 我尝试将其 css 设置为:position: fix
我正在尝试修改这个 Digiben 样本,以便获得从一个点(撞击点)产生并向上漂浮的粒子效果,有点像火的 Spark 。样本中的粒子在一个圆圈内旋转......我已经尝试删除余弦/正弦函数并将它们替换
我正在开发我的第一个游戏引擎,并尝试实现 GPU 粒子系统。我以前在 CPU 上实现过一个,但现在我正在努力提高它的效率。具体来说,我的问题是在一生中产生粒子。 由于我正在为粒子引擎处理帧缓冲区纹理,
我正在创建一个网络应用程序,该应用程序具有交互式背景,粒子会四处弹跳。在任何时候,屏幕上都有大约 200 个圆形粒子,最多大约 800 个粒子。为粒子运行的一些碰撞和效果是以下原型(prototype
我正在尝试让一些轨道物体留下痕迹。为此,我创建了一个粒子系统,其中包含三个几何体、三个点云和三个点云 Material : particleMaterial = new THREE.PointClou
如上所述,我正在使用 particles.js库,用于向我正在设计的网站上的 div 添加背景。 当页面加载时,正确的 div 将动画作为背景,但它总是开始得太“放大”。它似乎使用太大的默认屏幕尺寸,
我找不到是否可以限制粒子总数。 有什么办法吗? Particles.js Github 最佳答案 您可以修改 particles.js(第 750 行),在推送函数中添加额外的检查: /* -----
我正在尝试从主机ubuntu计算机上的远程Ubuntu计算机上运行CUDA粒子示例。 我遵循了本教程: http://devblogs.nvidia.com/parallelforall/remote
编辑嗨,我正在尝试实现粒子(或遗传)群优化。然而,我已经卡在第一步了…… 我对如何初始化粒子以及这些粒子(就代码而言)是什么感到困惑。 我已经找到了有关算法(单独)和实现的各种信息,但没有找到我想要的
我正在开发一个 2d android 策略游戏,它在 SurfaceView 上运行,所以我不能(或者我可以吗?)使用 LibGdx 的粒子系统。我想做一个下雨的效果,我的目标是这样的(http://
我正在使用粒子效果,它会到达您单击的位置并且不会停止。当我点击某个地方时,粒子就会相应地移动。然而,当我再次单击时,粒子开始越来越快地发挥其效果,我完全不明白为什么。我假设它在 SpellParent
好吧,我在 HTML 和 CSS 方面拥有丰富的经验,并且在 Javascript 方面也有一些经验(我可以编写基本功能并使用类似的语言进行编码)。 我正在寻找一些视觉项目,并且对进入粒子系统特别感兴
所以我有一些粒子(椭圆)在屏幕上跳来跳去。我试图让他们碰撞而不是互相超越。为了做到这一点,我必须循环遍历每个粒子,并将它与每个其他粒子的距离与嵌套在另一个 for 循环中的 for 循环进行比较,然后
我有使用 pygame 绘制的粒子和爆炸类。 爆炸代表一堆飞行的粒子。一个粒子最终会消失;当它的 ttl 属性变为 0 时,它不应该是可见的并且应该从 Explosion.particles 中移除。
我是一名优秀的程序员,十分优秀!