| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> | 2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 4 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> | 4 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
| 5 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> |
| 6 * Copyright (C) 2010 Zoltan Herczeg <zherczeg@webkit.org> | 6 * Copyright (C) 2010 Zoltan Herczeg <zherczeg@webkit.org> |
| 7 * Copyright (C) 2011 University of Szeged | 7 * Copyright (C) 2011 University of Szeged |
| 8 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> | 8 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> |
| 9 * | 9 * |
| 10 * Redistribution and use in source and binary forms, with or without | 10 * Redistribution and use in source and binary forms, with or without |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "platform/graphics/filters/SpotLightSource.h" | 33 #include "platform/graphics/filters/SpotLightSource.h" |
| 34 | 34 |
| 35 #include "platform/text/TextStream.h" | 35 #include "platform/text/TextStream.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 // spot-light edge darkening depends on an absolute treshold | |
| 40 // according to the SVG 1.1 SE light regression tests | |
| 41 static const float antiAliasTreshold = 0.016f; | |
| 42 | |
| 43 void SpotLightSource::initPaintingData(PaintingData& paintingData) const | |
| 44 { | |
| 45 paintingData.privateColorVector = paintingData.colorVector; | |
| 46 paintingData.directionVector.setX(m_direction.x() - m_position.x()); | |
| 47 paintingData.directionVector.setY(m_direction.y() - m_position.y()); | |
| 48 paintingData.directionVector.setZ(m_direction.z() - m_position.z()); | |
| 49 paintingData.directionVector.normalize(); | |
| 50 | |
| 51 if (!m_limitingConeAngle) { | |
| 52 paintingData.coneCutOffLimit = 0.0f; | |
| 53 paintingData.coneFullLight = -antiAliasTreshold; | |
| 54 } else { | |
| 55 float limitingConeAngle = m_limitingConeAngle; | |
| 56 if (limitingConeAngle < 0.0f) | |
| 57 limitingConeAngle = -limitingConeAngle; | |
| 58 if (limitingConeAngle > 90.0f) | |
| 59 limitingConeAngle = 90.0f; | |
| 60 paintingData.coneCutOffLimit = cosf(deg2rad(180.0f - limitingConeAngle))
; | |
| 61 paintingData.coneFullLight = paintingData.coneCutOffLimit - antiAliasTre
shold; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void SpotLightSource::updatePaintingData(PaintingData& paintingData, int x, int
y, float z) const | |
| 66 { | |
| 67 paintingData.lightVector.setX(m_position.x() - x); | |
| 68 paintingData.lightVector.setY(m_position.y() - y); | |
| 69 paintingData.lightVector.setZ(m_position.z() - z); | |
| 70 paintingData.lightVectorLength = paintingData.lightVector.length(); | |
| 71 | |
| 72 float cosineOfAngle = (paintingData.lightVector * paintingData.directionVect
or) / paintingData.lightVectorLength; | |
| 73 if (cosineOfAngle > paintingData.coneCutOffLimit) { | |
| 74 // No light is produced, scanlines are not updated | |
| 75 paintingData.colorVector.setX(0.0f); | |
| 76 paintingData.colorVector.setY(0.0f); | |
| 77 paintingData.colorVector.setZ(0.0f); | |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 // Set the color of the pixel | |
| 82 float lightStrength; | |
| 83 if (1.0f == m_specularExponent) { | |
| 84 lightStrength = -cosineOfAngle; // -cosineOfAngle ^ 1 == -cosineOfAngle | |
| 85 } else { | |
| 86 lightStrength = powf(-cosineOfAngle, m_specularExponent); | |
| 87 } | |
| 88 | |
| 89 if (cosineOfAngle > paintingData.coneFullLight) | |
| 90 lightStrength *= (paintingData.coneCutOffLimit - cosineOfAngle) / (paint
ingData.coneCutOffLimit - paintingData.coneFullLight); | |
| 91 | |
| 92 if (lightStrength > 1.0f) | |
| 93 lightStrength = 1.0f; | |
| 94 | |
| 95 paintingData.colorVector.setX(paintingData.privateColorVector.x() * lightStr
ength); | |
| 96 paintingData.colorVector.setY(paintingData.privateColorVector.y() * lightStr
ength); | |
| 97 paintingData.colorVector.setZ(paintingData.privateColorVector.z() * lightStr
ength); | |
| 98 } | |
| 99 | |
| 100 bool SpotLightSource::setPosition(const FloatPoint3D& position) | 39 bool SpotLightSource::setPosition(const FloatPoint3D& position) |
| 101 { | 40 { |
| 102 if (m_position == position) | 41 if (m_position == position) |
| 103 return false; | 42 return false; |
| 104 m_position = position; | 43 m_position = position; |
| 105 return true; | 44 return true; |
| 106 } | 45 } |
| 107 | 46 |
| 108 bool SpotLightSource::setPointsAt(const FloatPoint3D& direction) | 47 bool SpotLightSource::setPointsAt(const FloatPoint3D& direction) |
| 109 { | 48 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 140 { | 79 { |
| 141 ts << "[type=SPOT-LIGHT] "; | 80 ts << "[type=SPOT-LIGHT] "; |
| 142 ts << "[position=\"" << position() << "\"]"; | 81 ts << "[position=\"" << position() << "\"]"; |
| 143 ts << "[direction=\"" << direction() << "\"]"; | 82 ts << "[direction=\"" << direction() << "\"]"; |
| 144 ts << "[specularExponent=\"" << specularExponent() << "\"]"; | 83 ts << "[specularExponent=\"" << specularExponent() << "\"]"; |
| 145 ts << "[limitingConeAngle=\"" << limitingConeAngle() << "\"]"; | 84 ts << "[limitingConeAngle=\"" << limitingConeAngle() << "\"]"; |
| 146 return ts; | 85 return ts; |
| 147 } | 86 } |
| 148 | 87 |
| 149 }; // namespace blink | 88 }; // namespace blink |
| OLD | NEW |