From 7e1523414538e4a3d440dce242694c2f6123c691 Mon Sep 17 00:00:00 2001 From: sjfricke Date: Sun, 6 May 2018 23:27:41 -0500 Subject: [PATCH] cleaned up particlefire example really dug into example to learn and just _leaving the example better then I found it_ but cleaning up some unused values and swizzle redudency in shaders. Tested on desktop and android --- data/shaders/particlefire/normalmap.frag | 6 ++--- data/shaders/particlefire/normalmap.frag.spv | Bin 2948 -> 3020 bytes data/shaders/particlefire/normalmap.vert | 22 +++++++++---------- data/shaders/particlefire/normalmap.vert.spv | Bin 4748 -> 4720 bytes data/shaders/particlefire/particle.frag | 3 +-- data/shaders/particlefire/particle.vert | 3 +-- examples/particlefire/particlefire.cpp | 2 -- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/data/shaders/particlefire/normalmap.frag b/data/shaders/particlefire/normalmap.frag index 276490a8..564aed72 100644 --- a/data/shaders/particlefire/normalmap.frag +++ b/data/shaders/particlefire/normalmap.frag @@ -11,8 +11,8 @@ layout (binding = 2) uniform sampler2D sNormalHeightMap; layout (location = 0) in vec2 inUV; layout (location = 1) in vec3 inLightVec; layout (location = 2) in vec3 inLightVecB; -layout (location = 5) in vec3 inLightDir; -layout (location = 6) in vec3 inViewVec; +layout (location = 3) in vec3 inLightDir; +layout (location = 4) in vec3 inViewVec; layout (location = 0) out vec4 outFragColor; @@ -41,4 +41,4 @@ void main(void) float specular = pow(max(dot(view, reflectDir), 0.0), 4.0); outFragColor = vec4((rgb * atten + (diffuse * rgb + 0.5 * specular * specularColor.rgb)) * atten, 1.0); -} +} \ No newline at end of file diff --git a/data/shaders/particlefire/normalmap.frag.spv b/data/shaders/particlefire/normalmap.frag.spv index 573db6316108a5b9f11857072aa263208784d853..2f63b771e1b52dcf1cc4ee1026e20da0af61db8b 100644 GIT binary patch delta 108 zcmZn>KO@e~%%sfDz`zKEyc4+(y0b8FF}VB0yZigQ`?$s@7Zk)7msIAY#^+?_rN*aZ s7NsVaWR|5eFt9LiAgRmDOU@}xK~k{sv?voJ%jAbl@{G)z8JU|o02f#v4*&oF delta 37 rcmX>j-XhM;%%sfDz`zKE922<@ZWdt_VPa&PtjR3T$hz5+xtRk1cTWa$ diff --git a/data/shaders/particlefire/normalmap.vert b/data/shaders/particlefire/normalmap.vert index f577b857..de0885bb 100644 --- a/data/shaders/particlefire/normalmap.vert +++ b/data/shaders/particlefire/normalmap.vert @@ -15,20 +15,18 @@ layout (binding = 0) uniform UBO mat4 model; mat4 normal; vec4 lightPos; - 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; -layout (location = 5) out vec3 outLightDir; -layout (location = 6) out vec3 outViewVec; +layout (location = 3) out vec3 outLightDir; +layout (location = 4) out vec3 outViewVec; void main(void) { @@ -42,18 +40,18 @@ void main(void) 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) * tbnMatrix; - vec3 lightDist = ubo.lightPos.xyz - inPos.xyz; - outLightVecB.x = dot(inTangent.xyz, lightDist); - outLightVecB.y = dot(inBiTangent.xyz, lightDist); + vec3 lightDist = ubo.lightPos.xyz - inPos; + outLightVecB.x = dot(inTangent, lightDist); + outLightVecB.y = dot(inBiTangent, 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); + outViewVec.y = dot(inBiTangent, inPos); + outViewVec.z = dot(inNormal, inPos); outUV = inUV; gl_Position = ubo.projection * ubo.model * vec4(inPos, 1.0); -} +} \ No newline at end of file diff --git a/data/shaders/particlefire/normalmap.vert.spv b/data/shaders/particlefire/normalmap.vert.spv index ed9ae59eb67c282be5064278dcc7ae23fe8a007c..48d175fb6e25e3958c2daef2e2b1e73d9a507a5c 100644 GIT binary patch delta 157 zcmeBC{h-3l%%sfDz`zKEyc4-ky0b8FF}VB0yZigQ`?$s@7Zk)7msIAY#^+?_rN*aZ z7NsVaWR|5eFt9LiAgRmDOU@}xK~gaBa_{B}Mis`%JD5&Pp2F(73=9n1Fua+QRg#IFnPDMNfNQfZdptJ)pY$n9 delta 180 zcmeyM(xb}F%%sfDz`zKE922=uPL^Tp5oKdwW8h(6U|<2_}AL)fuJP z7}yyW0)-iYI6WsmAU`v&BsjAw708`@n(3sV2Lmfyt1?jV!sLm}-i)l1?=r_TvQ4&S sF$b%FnZOM)X>uV;p)fmG7l;qTT$?|#NHTG=fUV;KO0aDfWRK?t0K-}y4FCWD diff --git a/data/shaders/particlefire/particle.frag b/data/shaders/particlefire/particle.frag index 869e78f2..2277b702 100644 --- a/data/shaders/particlefire/particle.frag +++ b/data/shaders/particlefire/particle.frag @@ -11,7 +11,6 @@ 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; void main () @@ -43,4 +42,4 @@ void main () } outFragColor.rgb = color.rgb * inColor.rgb * alpha; -} +} \ No newline at end of file diff --git a/data/shaders/particlefire/particle.vert b/data/shaders/particlefire/particle.vert index ffa209f5..97aea3e3 100644 --- a/data/shaders/particlefire/particle.vert +++ b/data/shaders/particlefire/particle.vert @@ -44,6 +44,5 @@ void main () // 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; - + gl_PointSize = ubo.viewportDim.x * projectedCorner.x / projectedCorner.w; } \ No newline at end of file diff --git a/examples/particlefire/particlefire.cpp b/examples/particlefire/particlefire.cpp index e013c47d..ae80f612 100644 --- a/examples/particlefire/particlefire.cpp +++ b/examples/particlefire/particlefire.cpp @@ -106,7 +106,6 @@ public: glm::mat4 model; glm::mat4 normal; glm::vec4 lightPos = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f); - glm::vec4 cameraPos; } uboEnv; struct { @@ -709,7 +708,6 @@ public: uboEnv.projection = uboVS.projection; uboEnv.model = uboVS.model; uboEnv.normal = glm::inverseTranspose(uboEnv.model); - uboEnv.cameraPos = glm::vec4(0.0, 0.0, zoom, 0.0); memcpy(uniformBuffers.environment.mapped, &uboEnv, sizeof(uboEnv)); }