1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include "Lighting.h" 20 #include "Properties.h" 21 22 namespace android { 23 namespace uirenderer { 24 25 class LightingInfo { 26 public: 27 getLightRadius()28 static float getLightRadius() { 29 if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) { 30 return Properties::overrideLightRadius; 31 } 32 return mLightRadius; 33 } 34 getAmbientShadowAlpha()35 static uint8_t getAmbientShadowAlpha() { 36 if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) { 37 return Properties::overrideAmbientShadowStrength; 38 } 39 return mAmbientShadowAlpha; 40 } 41 getSpotShadowAlpha()42 static uint8_t getSpotShadowAlpha() { 43 if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) { 44 return Properties::overrideSpotShadowStrength; 45 } 46 return mSpotShadowAlpha; 47 } 48 getLightCenter()49 static Vector3 getLightCenter() { 50 if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) { 51 Vector3 adjustedLightCenter = mLightCenter; 52 if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) { 53 // negated since this shifts up 54 adjustedLightCenter.y = -Properties::overrideLightPosY; 55 } 56 if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) { 57 adjustedLightCenter.z = Properties::overrideLightPosZ; 58 } 59 return adjustedLightCenter; 60 } 61 return mLightCenter; 62 } 63 getLightCenterRaw()64 static Vector3 getLightCenterRaw() { 65 return mLightCenter; 66 } 67 setLightCenterRaw(const Vector3 & lightCenter)68 static void setLightCenterRaw(const Vector3& lightCenter) { 69 mLightCenter = lightCenter; 70 } 71 updateLighting(const LightGeometry & lightGeometry,const LightInfo & lightInfo)72 static void updateLighting(const LightGeometry& lightGeometry, const LightInfo& lightInfo) { 73 mLightRadius = lightGeometry.radius; 74 mAmbientShadowAlpha = lightInfo.ambientShadowAlpha; 75 mSpotShadowAlpha = lightInfo.spotShadowAlpha; 76 mLightCenter = lightGeometry.center; 77 } 78 private: 79 static float mLightRadius; 80 static uint8_t mAmbientShadowAlpha; 81 static uint8_t mSpotShadowAlpha; 82 static Vector3 mLightCenter; 83 }; 84 85 } /* namespace uirenderer */ 86 } /* namespace android */ 87