CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisLightDef.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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-2022 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),
55 kOverrideAngles = (1 << 4),
57 kOverrideShadow = (1 << 6),
59 };
60 // Type of light
62 {
65 kSpot
67 // Light position
69 // Light direction vector
71 // Light color
73 // Attenuations
77 // Attenuation limits
80 // Spot light parameters
83 // Factor for specular highlighting
85 // Shadow map parameters
89 // Flags
91
92 void setLightOn(bool bSet) { SETBIT(m_lightFlags, kLightEnabled, bSet); }
93 bool isLightOn() const { return GETBIT(m_lightFlags, kLightEnabled); }
94
97
98 void enableShadows(bool bSet) { SETBIT(m_lightFlags, kLightShadows, bSet); }
100
101 // Setup light defaults
103 {
107 m_color.set(0.0f, 0.0f, 0.0f);
109 m_linearAttenuation = 0.0f;
114 m_specularFactor = 0.0f;
115 m_shadowMapSize = 256;
117 m_shadowSamples = 16;
118 m_lightFlags = 0;
119 }
120
121 // Partial data apply
123 {
124 if (nMod != 0xFFFFFFFF)
125 {
126 if (GETBIT(nMod, kOverrideVisibility))
128 if (GETBIT(nMod, kOverrideOrientation))
131 if (GETBIT(nMod, kOverrideColor))
132 m_color = l.m_color;
133 if (GETBIT(nMod, kOverrideAttenuation))
140 if (GETBIT(nMod, kOverrideAngles))
145 if (GETBIT(nMod, kOverrideShadow))
150 }
151 else
152 *this = l;
153 return *this;
154 }
155
156 OdUInt32 diff(const OdTrVisLightDef &dl2, bool bFinFirstDiff = false) const
157 {
158 if (m_type != dl2.m_type)
159 return 0xFFFFFFFF;
160 OdUInt32 axxum = 0;
161 if (isLightOn() != dl2.isLightOn())
162 { if (bFinFirstDiff)
163 return 0xFFFFFFFF;
165 }
167 { if (bFinFirstDiff)
168 return 0xFFFFFFFF;
170 }
171 if (m_color != dl2.m_color)
172 { if (bFinFirstDiff)
173 return 0xFFFFFFFF;
174 SETBIT_1(axxum, kOverrideColor);
175 }
182 { if (bFinFirstDiff)
183 return 0xFFFFFFFF;
185 }
187 { if (bFinFirstDiff)
188 return 0xFFFFFFFF;
190 }
192 { if (bFinFirstDiff)
193 return 0xFFFFFFFF;
195 }
196 if ((shadowsEnabled() != dl2.shadowsEnabled()) || (m_shadowMapSize != dl2.m_shadowMapSize) ||
198 { if (bFinFirstDiff)
199 return 0xFFFFFFFF;
201 }
202 return axxum;
203 }
204
205 bool operator ==(const OdTrVisLightDef &dl2) const
206 { return diff(dl2, true) == 0; }
207 bool operator !=(const OdTrVisLightDef &dl2) const
208 { return diff(dl2, true) != 0; }
209
210 void save(OdGsFiler *pFiler) const;
211 void load(OdGsFiler *pFiler);
212};
213
214inline void OdTrVisLightDef::save(OdGsFiler *pFiler) const {
215 pFiler->wrUInt8 ((OdUInt8)m_type );
216 pFiler->wrPoint3d (m_position );
217 pFiler->wrVector3d(m_direction );
218 for (int nColorElem = 0; nColorElem < 4; nColorElem++)
219 pFiler->wrFloat (m_color[nColorElem] );
221 pFiler->wrFloat (m_linearAttenuation );
225 pFiler->wrFloat (m_spotCutoff );
226 pFiler->wrFloat (m_spotExponent );
227 pFiler->wrFloat (m_specularFactor );
228 pFiler->wrUInt16 (m_shadowMapSize );
229 pFiler->wrUInt16 (m_shadowSoftness );
230 pFiler->wrUInt16 (m_shadowSamples );
231 pFiler->wrUInt16 (m_lightFlags );
232}
233
234inline void OdTrVisLightDef::load(OdGsFiler *pFiler) {
235 m_type = (LightType)pFiler->rdUInt8();
236 pFiler->rdPoint3d(m_position);
237 pFiler->rdVector3d(m_direction);
238 for (int nColorElem = 0; nColorElem < 4; nColorElem++)
239 m_color[nColorElem] = pFiler->rdFloat();
240 m_constantAttenuation = pFiler->rdFloat();
241 m_linearAttenuation = pFiler->rdFloat();
244 m_endAttenuationLimit = pFiler->rdFloat();
245 m_spotCutoff = pFiler->rdFloat();
246 m_spotExponent = pFiler->rdFloat();
247 m_specularFactor = pFiler->rdFloat();
248 m_shadowMapSize = pFiler->rdUInt16();
249 m_shadowSoftness = pFiler->rdUInt16();
250 m_shadowSamples = pFiler->rdUInt16();
251 m_lightFlags = pFiler->rdUInt16();
252}
253
254#include "TD_PackPop.h"
255
256#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
OD_FORCEINLINE bool OdTrVisFPEqual(float a, float b, float tol=1.e-8f)
Definition: TrVisDefs.h:241
bool isEqualTo(const OdGePoint3d &point, const OdGeTol &tol=OdGeContext::gTol) const
static GE_STATIC_EXPORT const OdGePoint3d kOrigin
Definition: GePoint3d.h:106
static GE_STATIC_EXPORT const OdGeVector3d kZAxis
Definition: GeVector3d.h:103
bool isEqualTo(const OdGeVector3d &vect, const OdGeTol &tol=OdGeContext::gTol) const
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 float rdFloat() const
virtual void wrUInt8(OdUInt8 val)
virtual void rdPoint3d(OdGePoint3d &pt) const
virtual OdUInt16 rdUInt16() const
virtual void wrVector3d(const OdGeVector3d &vec)
bool shadowsEnabled() const
Definition: TrVisLightDef.h:99
OdGeVector3d m_direction
Definition: TrVisLightDef.h:70
OdUInt16 m_shadowSoftness
Definition: TrVisLightDef.h:87
enum OdTrVisLightDef::LightType m_type
OdUInt32 diff(const OdTrVisLightDef &dl2, bool bFinFirstDiff=false) const
OdTrVisMaterialColor m_color
Definition: TrVisLightDef.h:72
void enableShadows(bool bSet)
Definition: TrVisLightDef.h:98
OdGePoint3d m_position
Definition: TrVisLightDef.h:68
OdTrVisLightDef & apply(OdUInt32 nMod, const OdTrVisLightDef &l)
OdUInt16 m_lightFlags
Definition: TrVisLightDef.h:90
OdUInt16 m_shadowSamples
Definition: TrVisLightDef.h:88
bool isLightOn() const
Definition: TrVisLightDef.h:93
float m_startAttenuationLimit
Definition: TrVisLightDef.h:78
bool operator==(const OdTrVisLightDef &dl2) const
bool attenuationLimitsEnabled() const
Definition: TrVisLightDef.h:96
void load(OdGsFiler *pFiler)
bool operator!=(const OdTrVisLightDef &dl2) const
float m_endAttenuationLimit
Definition: TrVisLightDef.h:79
float m_linearAttenuation
Definition: TrVisLightDef.h:75
void enableAttenuationLimits(bool bSet)
Definition: TrVisLightDef.h:95
void setLightOn(bool bSet)
Definition: TrVisLightDef.h:92
void save(OdGsFiler *pFiler) const
OdUInt16 m_shadowMapSize
Definition: TrVisLightDef.h:86
float m_specularFactor
Definition: TrVisLightDef.h:84
float m_constantAttenuation
Definition: TrVisLightDef.h:74
float m_quadraticAttenuation
Definition: TrVisLightDef.h:76
void set(float r, float g, float b)