Updated particle fire shaders (Fixes #259)
This commit is contained in:
parent
a88ddff390
commit
ef26748142
8 changed files with 45 additions and 41 deletions
|
|
@ -21,7 +21,7 @@ void main(void)
|
|||
vec3 specularColor = vec3(0.85, 0.5, 0.0);
|
||||
|
||||
float invRadius = 1.0/lightRadius;
|
||||
float ambient = 0.0;
|
||||
float ambient = 0.25;
|
||||
|
||||
vec3 rgb, normal;
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -18,6 +18,12 @@ layout (binding = 0) uniform UBO
|
|||
vec4 cameraPos;
|
||||
} ubo;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_PointSize;
|
||||
};
|
||||
|
||||
layout (location = 0) out vec2 outUV;
|
||||
layout (location = 1) out vec3 outLightVec;
|
||||
layout (location = 2) out vec3 outLightVecB;
|
||||
|
|
@ -26,28 +32,28 @@ layout (location = 6) out vec3 outViewVec;
|
|||
|
||||
void main(void)
|
||||
{
|
||||
vec3 vertexPosition = vec3(ubo.model * vec4(inPos, 1.0));
|
||||
outLightDir = normalize(ubo.lightPos.xyz - vertexPosition);
|
||||
vec3 vertexPosition = vec3(ubo.model * vec4(inPos, 1.0));
|
||||
outLightDir = normalize(ubo.lightPos.xyz - vertexPosition);
|
||||
|
||||
// Setup (t)angent-(b)inormal-(n)ormal matrix for converting
|
||||
// object coordinates into tangent space
|
||||
mat3 tbnMatrix;
|
||||
tbnMatrix[0] = mat3(ubo.normal) * inTangent;
|
||||
tbnMatrix[1] = mat3(ubo.normal) * inBiTangent;
|
||||
tbnMatrix[2] = mat3(ubo.normal) * inNormal;
|
||||
// Setup (t)angent-(b)inormal-(n)ormal matrix for converting
|
||||
// object coordinates into tangent space
|
||||
mat3 tbnMatrix;
|
||||
tbnMatrix[0] = mat3(ubo.normal) * inTangent;
|
||||
tbnMatrix[1] = mat3(ubo.normal) * inBiTangent;
|
||||
tbnMatrix[2] = mat3(ubo.normal) * inNormal;
|
||||
|
||||
outLightVec.xyz = vec3(ubo.lightPos.xyz - vertexPosition.xyz) * tbnMatrix;
|
||||
outLightVec.xyz = vec3(ubo.lightPos.xyz - vertexPosition.xyz) * tbnMatrix;
|
||||
|
||||
vec3 lightDist = ubo.lightPos.xyz - inPos.xyz;
|
||||
outLightVecB.x = dot(inTangent.xyz, lightDist);
|
||||
outLightVecB.y = dot(inBiTangent.xyz, lightDist);
|
||||
outLightVecB.z = dot(inNormal, lightDist);
|
||||
vec3 lightDist = ubo.lightPos.xyz - inPos.xyz;
|
||||
outLightVecB.x = dot(inTangent.xyz, lightDist);
|
||||
outLightVecB.y = dot(inBiTangent.xyz, lightDist);
|
||||
outLightVecB.z = dot(inNormal, lightDist);
|
||||
|
||||
outViewVec.x = dot(inTangent, inPos.xyz);
|
||||
outViewVec.y = dot(inBiTangent, inPos.xyz);
|
||||
outViewVec.z = dot(inNormal, inPos.xyz);
|
||||
outViewVec.x = dot(inTangent, inPos.xyz);
|
||||
outViewVec.y = dot(inBiTangent, inPos.xyz);
|
||||
outViewVec.z = dot(inNormal, inPos.xyz);
|
||||
|
||||
outUV = inUV;
|
||||
outUV = inUV;
|
||||
|
||||
gl_Position = ubo.projection * ubo.model * vec4(inPos, 1.0);
|
||||
gl_Position = ubo.projection * ubo.model * vec4(inPos, 1.0);
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -7,10 +7,9 @@ layout (binding = 1) uniform sampler2D samplerSmoke;
|
|||
layout (binding = 2) uniform sampler2D samplerFire;
|
||||
|
||||
layout (location = 0) in vec4 inColor;
|
||||
layout (location = 1) in float inPointSize;
|
||||
layout (location = 2) in float inAlpha;
|
||||
layout (location = 3) in flat int inType;
|
||||
layout (location = 4) in float inRotation;
|
||||
layout (location = 1) in float inAlpha;
|
||||
layout (location = 2) in flat int inType;
|
||||
layout (location = 3) in float inRotation;
|
||||
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
|
@ -25,7 +24,7 @@ void main ()
|
|||
float rotCenter = 0.5;
|
||||
float rotCos = cos(inRotation);
|
||||
float rotSin = sin(inRotation);
|
||||
vec2 rotUV = vec2(
|
||||
vec2 rotUV = vec2(
|
||||
rotCos * (gl_PointCoord.x - rotCenter) + rotSin * (gl_PointCoord.y - rotCenter) + rotCenter,
|
||||
rotCos * (gl_PointCoord.y - rotCenter) - rotSin * (gl_PointCoord.x - rotCenter) + rotCenter);
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -11,10 +11,9 @@ layout (location = 4) in float inRotation;
|
|||
layout (location = 5) in int inType;
|
||||
|
||||
layout (location = 0) out vec4 outColor;
|
||||
layout (location = 1) out float outPointSize;
|
||||
layout (location = 2) out float outAlpha;
|
||||
layout (location = 3) out flat int outType;
|
||||
layout (location = 4) out float outRotation;
|
||||
layout (location = 1) out float outAlpha;
|
||||
layout (location = 2) out flat int outType;
|
||||
layout (location = 3) out float outRotation;
|
||||
|
||||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
|
|
@ -24,27 +23,27 @@ layout (binding = 0) uniform UBO
|
|||
float pointSize;
|
||||
} ubo;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_PointSize;
|
||||
};
|
||||
|
||||
void main ()
|
||||
{
|
||||
gl_PointSize = ubo.pointSize;
|
||||
outColor = inColor;
|
||||
outAlpha = inAlpha;
|
||||
outType = inType;
|
||||
outRotation = inRotation;
|
||||
|
||||
vec4 eyePos = ubo.modelview * vec4(inPos.xyz, 1.0);
|
||||
vec4 projVoxel = ubo.projection * vec4(ubo.pointSize, ubo.pointSize, eyePos.z, eyePos.w);
|
||||
vec2 projSize = ubo.viewportDim * projVoxel.xy / projVoxel.w;
|
||||
|
||||
outPointSize = inSize * 0.25 * (projSize.x + projSize.y);
|
||||
|
||||
gl_PointSize = outPointSize;
|
||||
|
||||
gl_Position = ubo.projection * ubo.modelview * vec4(inPos.xyz, 1.0);
|
||||
|
||||
float pointDist = (gl_Position.w == 0.0) ? 0.00001 : gl_Position.w;
|
||||
float viewportAR = ubo.viewportDim.x / ubo.viewportDim.y;
|
||||
|
||||
gl_PointSize = (((inSize * 2048.0 * viewportAR) / pointDist) * viewportAR);
|
||||
// Base size of the point sprites
|
||||
float spriteSize = 8.0 * inSize;
|
||||
|
||||
// Scale particle size depending on camera projection
|
||||
vec4 eyePos = ubo.modelview * vec4(inPos.xyz, 1.0);
|
||||
vec4 projectedCorner = ubo.projection * vec4(0.5 * spriteSize, 0.5 * spriteSize, eyePos.z, eyePos.w);
|
||||
gl_PointSize = ubo.viewportDim.x * projectedCorner.x / projectedCorner.w;
|
||||
|
||||
}
|
||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue