CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
TrVisLightDef.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23// GLES2 device light definition
24
25#ifndef ODTRVISLIGHTDEF
26#define ODTRVISLIGHTDEF
27
28#include "TD_PackPush.h"
29
30#include "TrVisMaterialColor.h"
31#include "Ge/GeVector3d.h"
32#include "Ge/GePoint3d.h"
33#include "Gs/GsFiler.h"
34
39{
40 // Flags
42 {
43 kLightEnabled = (1 << 0), // Light is on
44 kLightUseLims = (1 << 1), // Enable attenuation limits
45 kLightShadows = (1 << 2) // Shadows casting enabled
46 };
47 // Overriders
49 {
50 // Never override type and 'default light' state
53 kOverrideColor = (1 << 2),
54 kOverrideTextrue = (1 << 3),
56 kOverrideAngles = (1 << 5),
58 kOverrideShadow = (1 << 7),
60 };
61 // Type of light
68 // Light position
70 // Light direction vector
72 // Light up-vector
74 // Light color
76 // Intensities texture
78 // Attenuations
82 // Attenuation limits
85 // Spot light parameters
88 // Factor for specular highlighting
90 // Shadow map parameters
94 // Flags
96
97 void setLightOn(bool bSet) { SETBIT(m_lightFlags, kLightEnabled, bSet); }
98 bool isLightOn() const { return GETBIT(m_lightFlags, kLightEnabled); }
99
102
103 void enableShadows(bool bSet) { SETBIT(m_lightFlags, kLightShadows, bSet); }
105
106 // Setup light defaults
127
128 // Partial data apply
165
166 OdUInt32 diff(const OdTrVisLightDef &dl2, bool bFinFirstDiff = false) const
167 {
168 if (m_type != dl2.m_type)
169 return 0xFFFFFFFF;
170 OdUInt32 axxum = 0;
171 if (isLightOn() != dl2.isLightOn())
172 { if (bFinFirstDiff)
173 return 0xFFFFFFFF;
175 }
176 if (!m_position.isEqualTo(dl2.m_position) || !m_direction.isEqualTo(dl2.m_direction) ||
177 !m_upVector.isEqualTo(dl2.m_upVector))
178 { if (bFinFirstDiff)
179 return 0xFFFFFFFF;
181 }
182 if (m_color != dl2.m_color)
183 { if (bFinFirstDiff)
184 return 0xFFFFFFFF;
185 SETBIT_1(axxum, kOverrideColor);
186 }
187 if (m_texture != dl2.m_texture)
188 { if (bFinFirstDiff)
189 return 0xFFFFFFFF;
191 }
198 { if (bFinFirstDiff)
199 return 0xFFFFFFFF;
201 }
203 { if (bFinFirstDiff)
204 return 0xFFFFFFFF;
206 }
208 { if (bFinFirstDiff)
209 return 0xFFFFFFFF;
211 }
212 if ((shadowsEnabled() != dl2.shadowsEnabled()) || (m_shadowMapSize != dl2.m_shadowMapSize) ||
214 { if (bFinFirstDiff)
215 return 0xFFFFFFFF;
217 }
218 return axxum;
219 }
220
221 void transformBy(const OdGeMatrix3d &xForm)
222 {
223 if (m_type > kDistant)
224 m_position.transformBy(xForm);
225 m_direction.transformBy(xForm);
226 m_upVector.transformBy(xForm);
227 }
228
229 bool operator ==(const OdTrVisLightDef &dl2) const
230 { return diff(dl2, true) == 0; }
231 bool operator !=(const OdTrVisLightDef &dl2) const
232 { return diff(dl2, true) != 0; }
233
234 void save(OdGsFiler *pFiler) const;
235 void load(OdGsFiler *pFiler);
236};
237
238inline void OdTrVisLightDef::save(OdGsFiler *pFiler) const {
239 pFiler->wrUInt8 ((OdUInt8)m_type );
240 pFiler->wrPoint3d (m_position );
241 pFiler->wrVector3d(m_direction );
242 pFiler->wrVector3d(m_upVector );
243 for (int nColorElem = 0; nColorElem < 4; nColorElem++)
244 pFiler->wrFloat (m_color[nColorElem] );
245 pFiler->wrUInt64 ((OdUInt64)m_texture );
247 pFiler->wrFloat (m_linearAttenuation );
251 pFiler->wrFloat (m_spotCutoff );
252 pFiler->wrFloat (m_spotExponent );
253 pFiler->wrFloat (m_specularFactor );
254 pFiler->wrUInt16 (m_shadowMapSize );
255 pFiler->wrUInt16 (m_shadowSoftness );
256 pFiler->wrUInt16 (m_shadowSamples );
257 pFiler->wrUInt16 (m_lightFlags );
258}
259
260inline void OdTrVisLightDef::load(OdGsFiler *pFiler) {
261 m_type = (LightType)pFiler->rdUInt8();
262 pFiler->rdPoint3d(m_position);
263 pFiler->rdVector3d(m_direction);
264 pFiler->rdVector3d(m_upVector);
265 for (int nColorElem = 0; nColorElem < 4; nColorElem++)
266 m_color[nColorElem] = pFiler->rdFloat();
268 m_constantAttenuation = pFiler->rdFloat();
269 m_linearAttenuation = pFiler->rdFloat();
272 m_endAttenuationLimit = pFiler->rdFloat();
273 m_spotCutoff = pFiler->rdFloat();
274 m_spotExponent = pFiler->rdFloat();
275 m_specularFactor = pFiler->rdFloat();
276 m_shadowMapSize = pFiler->rdUInt16();
277 m_shadowSoftness = pFiler->rdUInt16();
278 m_shadowSamples = pFiler->rdUInt16();
279 m_lightFlags = pFiler->rdUInt16();
280}
281
282#include "TD_PackPop.h"
283
284#endif // ODTRVISLIGHTDEF
unsigned int OdUInt32
unsigned short OdUInt16
unsigned char OdUInt8
#define SETBIT(flags, bit, value)
Definition OdaDefs.h:516
#define GETBIT(flags, bit)
Definition OdaDefs.h:517
#define SETBIT_1(flags, bit)
Definition OdaDefs.h:520
const OdTrVisId kTrVisNullId
Definition TrVisDefs.h:141
OD_FORCEINLINE bool OdTrVisFPEqual(float a, float b, float tol=1.e-8f)
Definition TrVisDefs.h:276
OdTrVisId OdTrVisTextureId
Definition TrVisDefs.h:108
static GE_STATIC_EXPORT const OdGePoint3d kOrigin
Definition GePoint3d.h:106
static GE_STATIC_EXPORT const OdGeVector3d kZAxis
Definition GeVector3d.h:103
static GE_STATIC_EXPORT const OdGeVector3d kYAxis
Definition GeVector3d.h:102
virtual void wrPoint3d(const OdGePoint3d &pt)
virtual void wrFloat(float val)
virtual void wrUInt16(OdUInt16 val)
virtual void rdVector3d(OdGeVector3d &vec) const
virtual OdUInt8 rdUInt8() const
virtual OdUInt64 rdUInt64() const
virtual float rdFloat() const
virtual void wrUInt8(OdUInt8 val)
virtual void wrUInt64(OdUInt64 val)
virtual void rdPoint3d(OdGePoint3d &pt) const
virtual OdUInt16 rdUInt16() const
virtual void wrVector3d(const OdGeVector3d &vec)
bool shadowsEnabled() const
OdGeVector3d m_direction
OdUInt16 m_shadowSoftness
enum OdTrVisLightDef::LightType m_type
OdUInt32 diff(const OdTrVisLightDef &dl2, bool bFinFirstDiff=false) const
OdTrVisMaterialColor m_color
void enableShadows(bool bSet)
OdGePoint3d m_position
OdTrVisLightDef & apply(OdUInt32 nMod, const OdTrVisLightDef &l)
OdUInt16 m_lightFlags
OdUInt16 m_shadowSamples
bool isLightOn() const
float m_startAttenuationLimit
bool operator==(const OdTrVisLightDef &dl2) const
bool attenuationLimitsEnabled() const
void load(OdGsFiler *pFiler)
bool operator!=(const OdTrVisLightDef &dl2) const
float m_endAttenuationLimit
void transformBy(const OdGeMatrix3d &xForm)
float m_linearAttenuation
void enableAttenuationLimits(bool bSet)
OdGeVector3d m_upVector
void setLightOn(bool bSet)
void save(OdGsFiler *pFiler) const
OdUInt16 m_shadowMapSize
float m_constantAttenuation
OdTrVisTextureId m_texture
float m_quadraticAttenuation