简体   繁体   English

像广告牌的法线一样渲染球体(体积广告牌?)

[英]Render sphere like normals for billboard (volumetric billboard?)

I have a deferred rendering particle system and Im trying to improve the generation of the billboard's normals for the normal map pass. 我有一个延迟的渲染粒子系统,我正在尝试改善法线贴图传递的广告牌法线的生成。 Currently I render the billboard normals as a forward facing Z. When the light render passes draw the scene, they interact with the billboards moreso when the BB is facing the light (as expected). 目前,我将广告牌法线渲染为朝前的Z。当灯光渲染通过时绘制场景,它们在BB面向灯光时会与广告牌进行更多交互(如预期的那样)。

在此处输入图片说明

Here is what the normal pass looks like: 这是普通通行证的样子:

在此处输入图片说明

This works as expected... however I would like to better simulate a kind of volume effect on the particles. 这可以按预期工作……但是我想更好地模拟一种对粒子的体积效果。 I want to treat each billboard as if though its more sphere like. 我想将每个广告牌都当作一个更大的球体来对待。 My thinking is that the lighting interactions with the particles would be better as a sphere has a wider range of normal directions. 我的想法是,随着球体的法线方向范围更广,与粒子的光照交互作用会更好。 Ie Id like to mimic something like this (The white border would be a single billboard): 即我想模仿这样的东西(白色边框将是单个广告牌):

在此处输入图片说明

Is this a good idea? 这是一个好主意吗? I don't really know how to go about doing it. 我真的不知道该怎么做。

EDIT 编辑

I am using points for the rendering, and my current thinking is something like this: 我正在使用点进行渲染,而我目前的想法是这样的:

   normal.x = gl_PointCoord.x;
   normal.y = gl_PointCoord.y;
   normal.z = 1.0;

But the gl_PointCoord doesnt seem to be producing the effect i thought it does. 但是gl_PointCoord似乎并没有产生我认为的效果。 Screenshot below: 屏幕截图如下: 在此处输入图片说明

EDIT 2 编辑2

Hi guys, I still seem to be having problems. 大家好,我似乎仍然有问题。 The GLSL I am using now is as follows: 我现在使用的GLSL如下:

vec3 normal = vec3( gl_PointCoord.x * 2.0  - 1.0, 1.0 - gl_PointCoord.y * 2.0 , length(gl_PointCoord.xy) );
normal = normalize( normal );

在此处输入图片说明

But it still doesnt seem 100%. 但它似乎仍然不是100%。 For most cases it seems to work well. 在大多数情况下,它似乎运作良好。 However you can see a problem when I use a directional light which faces the billboards. 但是,当我使用面向广告牌的定向光时,您会看到一个问题。

在此处输入图片说明

Its as if though the lower left blue normals are not right. 好像左下方的蓝色法线不正确。 If you look at the regular sphere normals the lower left blue fades into black (indicating the lack of z power). 如果查看常规球体法线,则左下方的蓝色会逐渐变为黑色(表示缺少z功效)。 I think this is still what's missing. 我认为这仍然是缺少的东西。 Any ideas? 有任何想法吗?

EDIT 3 编辑3

Figured out what was wrong. 找出问题所在。 During my normal pass I forgot to properly encode the normal and then decode it later. 在我的普通传递过程中,我忘了正确编码普通编码,然后再对其进行解码。

// Encoding pass
vec3 normal = vec3( gl_PointCoord.x * 4.0 - 2.0, 2.0 - gl_PointCoord.y * 4.0, 1.0 );
normal = normalize( normal );
normal = normal * 0.5 + 0.5;

// Decoding pass
vec3 normal = texture2D( normalMap, vUv ).xyz;
normal = normal.xyz * 2.0 - 1.0;

The reason your gl_PointCoord usage doesn't turn out like you wanted is that the range of gl_PointCoord is 0.0 to 1.0, not -1.0 to 1.0. gl_PointCoord用法未如您所愿的原因是gl_PointCoord的范围是0.0到1.0,而不是-1.0到1.0。

Just subtract 0.5 to make it balanced about 0.0. 只需减去0.5,即可使其平衡到约0.0。 If you also multiply it by 2 it will have the range -1.0 to 1.0. 如果您也将其乘以2,则范围为-1.0到1.0。

You may also want to normalize the resulting vector (not doing so can cause unwanted brightness variations as the length of the vector changes due to the z-component being fixed to 1.0). 您可能还需要normalize结果向量(不这样做会导致不必要的亮度变化,因为向量的长度由于z分量固定为1.0而改变)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM