diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-20 12:11:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-20 12:11:59 +0400 |
commit | 586f202eacf0ce06a38dc95d7b0300f85d47457c (patch) | |
tree | 7bff8dcd4e7103941f6ba3c88e340e9657733179 /source/blender | |
parent | fc1164c2236654a74789cf767e8efc73d5599ab1 (diff) |
minor speedup for the glare compositor node
- pre calculate the UV dot product
- use image width and height converted to floats in the inner loop.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp | 19 | ||||
-rw-r--r-- | source/blender/nodes/composite/nodes/node_composite_lensdist.c | 11 |
2 files changed, 16 insertions, 14 deletions
diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp index 1e19c293314..02cc62d4bdd 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp @@ -72,19 +72,20 @@ void ScreenLensDistortionOperation::executePixel(float *outputColor, int x, int float tc[4] = {0, 0, 0, 0}; const float v = sc * ((y + 0.5f) - cy) / cy; const float u = sc * ((x + 0.5f) - cx) / cx; + const float uv_dot = u * u + v * v; int sta = 0, mid = 0, end = 0; - if ((t = 1.f - kr4 * (u * u + v * v)) >= 0.f) { + if ((t = 1.f - kr4 * uv_dot) >= 0.f) { d = 1.f / (1.f + sqrtf(t)); ln[0] = (u * d + 0.5f) * width - 0.5f, ln[1] = (v * d + 0.5f) * height - 0.5f; sta = 1; } - if ((t = 1.f - kg4 * (u * u + v * v)) >= 0.f) { + if ((t = 1.f - kg4 * uv_dot) >= 0.f) { d = 1.f / (1.f + sqrtf(t)); ln[2] = (u * d + 0.5f) * width - 0.5f, ln[3] = (v * d + 0.5f) * height - 0.5f; mid = 1; } - if ((t = 1.f - kb4 * (u * u + v * v)) >= 0.f) { + if ((t = 1.f - kb4 * uv_dot) >= 0.f) { d = 1.f / (1.f + sqrtf(t)); ln[4] = (u * d + 0.5f) * width - 0.5f, ln[5] = (v * d + 0.5f) * height - 0.5f; end = 1; @@ -103,10 +104,10 @@ void ScreenLensDistortionOperation::executePixel(float *outputColor, int x, int for (z = 0; z < ds; ++z) { const float tz = ((float)z + (jit ? BLI_frand() : 0.5f)) * sd; - t = 1.f - (kr4 + tz * drg) * (u * u + v * v); + t = 1.f - (kr4 + tz * drg) * uv_dot; d = 1.f / (1.f + sqrtf(t)); - const float nx = (u * d + 0.5f) * getWidth() - 0.5f; - const float ny = (v * d + 0.5f) * getHeight() - 0.5f; + const float nx = (u * d + 0.5f) * width - 0.5f; + const float ny = (v * d + 0.5f) * height - 0.5f; buffer->readCubic(color, nx, ny); tc[0] += (1.f - tz) * color[0], tc[1] += tz * color[1]; dr++, dg++; @@ -121,10 +122,10 @@ void ScreenLensDistortionOperation::executePixel(float *outputColor, int x, int for (z = 0; z < ds; ++z) { const float tz = ((float)z + (jit ? BLI_frand() : 0.5f)) * sd; - t = 1.f - (kg4 + tz * dgb) * (u * u + v * v); + t = 1.f - (kg4 + tz * dgb) * uv_dot; d = 1.f / (1.f + sqrtf(t)); - const float nx = (u * d + 0.5f) * getWidth() - 0.5f; - const float ny = (v * d + 0.5f) * getHeight() - 0.5f; + const float nx = (u * d + 0.5f) * width - 0.5f; + const float ny = (v * d + 0.5f) * height - 0.5f; buffer->readCubic(color, nx, ny); tc[1] += (1.f - tz) * color[1], tc[2] += tz * color[2]; dg++, db++; diff --git a/source/blender/nodes/composite/nodes/node_composite_lensdist.c b/source/blender/nodes/composite/nodes/node_composite_lensdist.c index 9b19ca6f5cf..7635a391441 100644 --- a/source/blender/nodes/composite/nodes/node_composite_lensdist.c +++ b/source/blender/nodes/composite/nodes/node_composite_lensdist.c @@ -98,19 +98,20 @@ static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb float d, t, ln[6] = {0, 0, 0, 0, 0, 0}; fRGB c1, tc = {0, 0, 0, 0}; const float u = sc*((x + 0.5f) - cx)/cx; + const float uv_dot = u * u + v * v; int sta = 0, mid = 0, end = 0; - if ((t = 1.f - kr*(u*u + v*v)) >= 0.f) { + if ((t = 1.f - kr*uv_dot) >= 0.f) { d = 1.f/(1.f + sqrtf(t)); ln[0] = (u*d + 0.5f)*dst->x - 0.5f, ln[1] = (v*d + 0.5f)*dst->y - 0.5f; sta = 1; } - if ((t = 1.f - kg*(u*u + v*v)) >= 0.f) { + if ((t = 1.f - kg*uv_dot) >= 0.f) { d = 1.f/(1.f + sqrtf(t)); ln[2] = (u*d + 0.5f)*dst->x - 0.5f, ln[3] = (v*d + 0.5f)*dst->y - 0.5f; mid = 1; } - if ((t = 1.f - kb*(u*u + v*v)) >= 0.f) { + if ((t = 1.f - kb*uv_dot) >= 0.f) { d = 1.f/(1.f + sqrtf(t)); ln[4] = (u*d + 0.5f)*dst->x - 0.5f, ln[5] = (v*d + 0.5f)*dst->y - 0.5f; end = 1; @@ -125,7 +126,7 @@ static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb for (z=0; z<ds; ++z) { const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd; - t = 1.f - (kr + tz*drg)*(u*u + v*v); + t = 1.f - (kr + tz*drg)*uv_dot; d = 1.f / (1.f + sqrtf(t)); qd_getPixelLerp(src, (u*d + 0.5f)*dst->x - 0.5f, (v*d + 0.5f)*dst->y - 0.5f, c1); if (src->type == CB_VAL) c1[1] = c1[2] = c1[0]; @@ -141,7 +142,7 @@ static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb for (z=0; z<ds; ++z) { const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd; - t = 1.f - (kg + tz*dgb)*(u*u + v*v); + t = 1.f - (kg + tz*dgb)*uv_dot; d = 1.f / (1.f + sqrtf(t)); qd_getPixelLerp(src, (u*d + 0.5f)*dst->x - 0.5f, (v*d + 0.5f)*dst->y - 0.5f, c1); if (src->type == CB_VAL) c1[1] = c1[2] = c1[0]; |