diff --git a/data/shaders/particlefire/normalmap.frag b/data/shaders/particlefire/normalmap.frag index 86266d45..276490a8 100644 --- a/data/shaders/particlefire/normalmap.frag +++ b/data/shaders/particlefire/normalmap.frag @@ -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; diff --git a/data/shaders/particlefire/normalmap.frag.spv b/data/shaders/particlefire/normalmap.frag.spv index d5c0565a..573db631 100644 Binary files a/data/shaders/particlefire/normalmap.frag.spv and b/data/shaders/particlefire/normalmap.frag.spv differ diff --git a/data/shaders/particlefire/normalmap.vert b/data/shaders/particlefire/normalmap.vert index 53a5914b..f577b857 100644 --- a/data/shaders/particlefire/normalmap.vert +++ b/data/shaders/particlefire/normalmap.vert @@ -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); } diff --git a/data/shaders/particlefire/normalmap.vert.spv b/data/shaders/particlefire/normalmap.vert.spv index 8dce1c09..ed9ae59e 100644 Binary files a/data/shaders/particlefire/normalmap.vert.spv and b/data/shaders/particlefire/normalmap.vert.spv differ diff --git a/data/shaders/particlefire/particle.frag b/data/shaders/particlefire/particle.frag index 4e7b186d..869e78f2 100644 --- a/data/shaders/particlefire/particle.frag +++ b/data/shaders/particlefire/particle.frag @@ -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); diff --git a/data/shaders/particlefire/particle.frag.spv b/data/shaders/particlefire/particle.frag.spv index 499e8ea3..7db275a2 100644 Binary files a/data/shaders/particlefire/particle.frag.spv and b/data/shaders/particlefire/particle.frag.spv differ diff --git a/data/shaders/particlefire/particle.vert b/data/shaders/particlefire/particle.vert index d64c669b..ffa209f5 100644 --- a/data/shaders/particlefire/particle.vert +++ b/data/shaders/particlefire/particle.vert @@ -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; } \ No newline at end of file diff --git a/data/shaders/particlefire/particle.vert.spv b/data/shaders/particlefire/particle.vert.spv index d1069977..1bf28d9c 100644 Binary files a/data/shaders/particlefire/particle.vert.spv and b/data/shaders/particlefire/particle.vert.spv differ