Skip to content

Commit 6276a64

Browse files
committed
Implement polygon light rotation, compose a colored default scene.
1 parent f6e2e75 commit 6276a64

File tree

13 files changed

+138
-33
lines changed

13 files changed

+138
-33
lines changed

src/apps/ch10_area_lights/ch10_area_lights/Material.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct PhongMaterialsBlock_glsl
5656

5757
DESCRIBE(PhongMaterialsBlock_glsl)
5858
{
59-
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), count);
59+
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), "count");
6060
GIVE_EX(aValue.spanMaterials(), "materials");
6161
}
6262

@@ -98,7 +98,7 @@ struct PbrMaterialsBlock_glsl
9898

9999
DESCRIBE(PbrMaterialsBlock_glsl)
100100
{
101-
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), count);
101+
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), "count");
102102
GIVE_EX(aValue.spanMaterials(), "materials");
103103
}
104104

src/apps/ch10_area_lights/ch10_area_lights/Scene.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <renderer/BufferLoad.h>
1414
#include <renderer/Uniforms.h>
1515

16+
#include <scenic/ColorPalettes.h>
17+
1618
#include <ui/ImguiUi.h>
1719
#include <ui/Widgets.h>
1820
#include <ui/Widgets-impl.h>
@@ -92,7 +94,7 @@ template <class T_witness>
9294
void describe(T_witness aWitness, Scene::TessellationControl & aValue)
9395
{
9496
GIVE_EX(make_Clamped(aValue.mPatchVertices, {.mMin = 1u, .mMax = (GLuint)aValue.mMaxPatchVertices}),
95-
PatchVertices);
97+
"PatchVertices");
9698
GIVE(OuterLevel);
9799
GIVE(InnerLevel);
98100

@@ -175,10 +177,10 @@ void Scene::setupLights()
175177
constexpr unsigned int tubeCount = 3;
176178
constexpr unsigned int bulbCount = 1;
177179
std::array<math::hdr::Rgb<GLfloat>, tubeCount + bulbCount> colors{{
178-
{0.55f, 0.05f, 0.05f},
179-
{0.13f, 0.64f, 0.62f},
180-
{1.f, 0.73f, 0.29f},
181-
{0.44f, 0.f, 0.37f},
180+
scenic::hdr::gNicePalette1_srgb[0],
181+
scenic::hdr::gNicePalette1_srgb[1],
182+
scenic::hdr::gNicePalette1_srgb[2],
183+
scenic::hdr::gNicePalette1_srgb[3],
182184
}};
183185
float height = 1.5f;
184186
float radius = 3.f;

src/apps/ch10_ltc/ch10_ltc/Material.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct PhongMaterialsBlock_glsl
5656

5757
DESCRIBE(PhongMaterialsBlock_glsl)
5858
{
59-
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), count);
59+
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), "count");
6060
GIVE_EX(aValue.spanMaterials(), "materials");
6161
}
6262

@@ -98,7 +98,7 @@ struct PbrMaterialsBlock_glsl
9898

9999
DESCRIBE(PbrMaterialsBlock_glsl)
100100
{
101-
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), count);
101+
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), "count");
102102
GIVE_EX(aValue.spanMaterials(), "materials");
103103
}
104104

src/apps/ch10_ltc/ch10_ltc/PlanarLights.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct alignas(16) CardLight_glsl
3333
// Note: in GLSL, we do not have struct matching the rect, but directly read it as 2x vec2
3434
// std140 rule 2.: alignment of vec2 is 2x4.
3535
alignas(8) math::Rectangle<GLfloat> mRect;
36+
//
37+
GLfloat mRotationX = 0.f;
38+
GLfloat mRotationZ = 0.f;
39+
3640
// Note: this member is actually matched to a GLSL struct.
3741
// We rely on LightColors_glsl struct to define its alignment
3842
renderer::LightColors_glsl mColors;
@@ -41,10 +45,14 @@ struct alignas(16) CardLight_glsl
4145

4246
DESCRIBE(CardLight_glsl)
4347
{
48+
auto pi = math::pi<GLfloat>;
49+
4450
GIVE(Height);
4551
GIVE(DoubleSided);
4652
GIVE(ClipHorizon);
4753
GIVE(Rect);
54+
GIVE_EX((Clamped<GLfloat>(aValue.mRotationX, -pi/2, pi/2)), "rotation X");
55+
GIVE_EX((Clamped<GLfloat>(aValue.mRotationZ, -pi, pi)), "rotation Z");
4856
GIVE_EX(aValue.mColors.mDiffuseColor, "diffuse color");
4957
GIVE_EX(aValue.mColors.mSpecularColor, "specular color");
5058
}

src/apps/ch10_ltc/ch10_ltc/Scene.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ template <class T_witness>
104104
void describe(T_witness aWitness, Scene::TessellationControl & aValue)
105105
{
106106
GIVE_EX(make_Clamped(aValue.mPatchVertices, {.mMin = 1u, .mMax = (GLuint)aValue.mMaxPatchVertices}),
107-
PatchVertices);
107+
"PatchVertices");
108108
GIVE(OuterLevel);
109109
GIVE(InnerLevel);
110110

@@ -261,6 +261,20 @@ renderer::LightsDataCommon transformLightsData(
261261
}
262262

263263

264+
math::hdr::Rgb<float> capColor(math::hdr::Rgb<float> aColor)
265+
{
266+
float maxElement = *aColor.getMaxMagnitudeElement();
267+
if (maxElement > 1)
268+
{
269+
return aColor / maxElement;
270+
}
271+
else
272+
{
273+
return aColor;
274+
}
275+
}
276+
277+
264278
void Scene::render(math::Size<2, int> aRenderResolution)
265279
{
266280
//
@@ -280,11 +294,14 @@ void Scene::render(math::Size<2, int> aRenderResolution)
280294
light.mRect.mDimension.width(),
281295
1.f,
282296
light.mRect.mDimension.height())
297+
* math::trans3d::rotateX(math::Radian<GLfloat>{light.mRotationX})
298+
* math::trans3d::rotateZ(math::Radian<GLfloat>{light.mRotationZ})
283299
* math::trans3d::translate<GLfloat>({
284300
light.mRect.mPosition.x(),
285301
light.mHeight,
286302
light.mRect.y()});
287-
entity.mColorFactor = light.mColors.mSpecularColor;
303+
// Encode to sRGB, because PlainColor.frag does not apply gamma correction
304+
entity.mColorFactor = math::encode_sRGB(capColor(light.mColors.mSpecularColor));
288305
}
289306
loadToBuffer(mEntities, mEntitiesBlockBuffer, graphics::BufferHint::StreamDraw);
290307

src/apps/ch10_ltc/ch10_ltc/Scene.h

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <renderer/VertexSpecification.h>
1919
#include <renderer/Drawing.h>
2020

21+
#include <scenic/ColorPalettes.h>
2122
#include <scenic/Shapes.h>
2223

2324

@@ -26,6 +27,8 @@ namespace ad {
2627

2728
constexpr math::hdr::Rgb<GLfloat> gBrickAlbedo{ 0.262f, 0.095f, 0.061f };
2829

30+
constexpr float gLightPowerScale = 8;
31+
constexpr float gPlaneRotation = math::Degree<GLfloat>(30.f).as<math::Radian>().value();
2932

3033
namespace graphics {
3134
class AppInterface;
@@ -150,18 +153,64 @@ struct Scene
150153
},
151154
};
152155
PlanarLightsBlock mLights{
153-
.mPlanarCount = 1,
156+
.mPlanarCount = 5,
154157
// We decode a sRGB 10% white (which is also perceptually ~10%)
155158
// to linear space for computation.
156159
.mAmbientColor = math::decode_sRGB(math::hdr::gWhite<float> *0.1f),
157160
.mPlanarLights{
158161
CardLight_glsl{
159-
.mHeight = 2.f,
162+
.mHeight = 3.5f,
160163
.mRect{
161-
.mPosition{0.f, 0.f},
164+
.mPosition{-2.f, -2.f},
165+
.mDimension{4.f, 4.f},
166+
},
167+
.mColors = renderer::makeLightColors(
168+
math::hdr::gWhite<GLfloat> *gLightPowerScale),
169+
},
170+
CardLight_glsl{
171+
.mHeight = -2.f + 2 * std::sin(gPlaneRotation),
172+
.mDoubleSided = true,
173+
.mRect{
174+
.mPosition{-3.f + 2 * (1 - std::cos(gPlaneRotation)), -1.f},
175+
.mDimension{2.f, 2.f},
176+
},
177+
.mRotationZ = -gPlaneRotation,
178+
.mColors = renderer::makeLightColors(
179+
math::decode_sRGB(scenic::hdr::gNicePalette1_srgb[0]) * gLightPowerScale),
180+
},
181+
CardLight_glsl{
182+
.mHeight = -2.f,
183+
.mDoubleSided = true,
184+
.mRect{
185+
.mPosition{1.f, -1.f},
186+
.mDimension{2.f, 2.f},
187+
},
188+
.mRotationZ = gPlaneRotation,
189+
.mColors = renderer::makeLightColors(
190+
math::decode_sRGB(scenic::hdr::gNicePalette1_srgb[1]) * gLightPowerScale),
191+
},
192+
CardLight_glsl{
193+
.mHeight = -2.f,
194+
.mDoubleSided = true,
195+
.mRect{
196+
.mPosition{-1.f, 1.f},
197+
.mDimension{2.f, 2.f},
198+
},
199+
.mRotationX = -gPlaneRotation,
200+
.mColors = renderer::makeLightColors(
201+
math::decode_sRGB(scenic::hdr::gNicePalette1_srgb[2]) * gLightPowerScale),
202+
},
203+
CardLight_glsl{
204+
.mHeight = -2.f + 2 * std::sin(gPlaneRotation),
205+
.mDoubleSided = true,
206+
.mRect{
207+
.mPosition{-1.f, -3.f + 2 * (1 - std::cos(gPlaneRotation))},
162208
.mDimension{2.f, 2.f},
163209
},
164-
}
210+
.mRotationX = gPlaneRotation,
211+
.mColors = renderer::makeLightColors(
212+
math::decode_sRGB(scenic::hdr::gNicePalette1_srgb[3]) * gLightPowerScale),
213+
},
165214
}
166215
};
167216
OrbitalCamera mOrbitalCamera;

src/apps/ch10_ltc/ch10_ltc/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ int main(int argc, const char * argv[])
2727
{
2828
spdlog::set_level(spdlog::level::debug);
2929

30-
ad::graphics::ApplicationGlfw application("ch10_ltc", 1080, 600,
31-
ad::graphics::ApplicationFlag::None,
32-
4, 6);
30+
ad::graphics::ApplicationGlfw application{
31+
"ch10_ltc", 1080, 600,
32+
ad::graphics::ApplicationFlag::None,
33+
4, 6,
34+
{ {GLFW_SAMPLES, 8} }};
3335
//glClearColor(1.f, 1.f, 1.f, 1.f);
3436

3537
// Ensures the messages are sent synchronously with the event triggering them

src/apps/ch10_ltc/ch10_ltc/resources/shaders/ch10_ltc_LightsBlock.glsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct CardLight
1919
bool clipHorizon;
2020
vec2 rectPosition;
2121
vec2 rectDimensions;
22+
float rotationX;
23+
float rotationZ;
2224
LightColors colors;
2325
};
2426

@@ -27,9 +29,14 @@ vec3[4] getPolygon(CardLight aCard)
2729
{
2830
vec3 result[4];
2931

32+
float rx = aCard.rotationX;
33+
float rz = aCard.rotationZ;
34+
3035
vec3 origin = vec3(aCard.rectPosition.x, aCard.height, aCard.rectPosition.y);
31-
vec3 w = vec3(aCard.rectDimensions.x, 0, 0);
32-
vec3 h = vec3(0, 0, aCard.rectDimensions.y);
36+
// TODO: in production, precompute the polygon vertices instead of
37+
// transforming each frame in each fragment
38+
vec3 w = aCard.rectDimensions.x * vec3(cos(rz), sin(rz), 0);
39+
vec3 h = aCard.rectDimensions.y * vec3(sin(rz) * sin(rx), -cos(rz) * sin(rx), cos(rx));
3340

3441
result[0] = origin;
3542
result[1] = origin + h;

src/apps/ch11_ssao/ch11_ssao/FrameGraph.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,31 @@ namespace ad {
6565

6666
DESCRIBE(FrameGraph::SphereSsaoControl)
6767
{
68-
GIVE_EX(make_Clamped(aValue.mDepthBias, { .mMax = 1.0f }), DepthBias);
69-
GIVE_EX(make_Clamped(aValue.mSphereRadius, { .mMax = 5.0f }), SphereRadius);
68+
GIVE_EX(make_Clamped(aValue.mDepthBias, { .mMax = 1.0f }), "DepthBias");
69+
GIVE_EX(make_Clamped(aValue.mSphereRadius, { .mMax = 5.0f }), "SphereRadius");
7070
GIVE(ReflectSamples);
7171
GIVE(Weighted);
72-
GIVE_EX(make_Clamped(aValue.mWeightFactor, { .mMax = 50.0f }), WeightFactor);
72+
GIVE_EX(make_Clamped(aValue.mWeightFactor, { .mMax = 50.0f }), "WeightFactor");
7373
GIVE(SphereInScreenSpace);
7474
GIVE(ScreenSpaceNonLinearDepth);
7575
}
7676

7777
DESCRIBE(FrameGraph::HemiSsaoControl)
7878
{
79-
GIVE_EX(make_Clamped(aValue.mDepthBias, { .mMax = 1.0f }), DepthBias);
80-
GIVE_EX(make_Clamped(aValue.mSphereRadius, { .mMax = 5.0f }), SphereRadius);
79+
GIVE_EX(make_Clamped(aValue.mDepthBias, { .mMax = 1.0f }), "DepthBias");
80+
GIVE_EX(make_Clamped(aValue.mSphereRadius, { .mMax = 5.0f }), "SphereRadius");
8181
GIVE(ImportanceSampling);
8282
GIVE(RotateSamples);
8383
GIVE(WeightDistance);
8484
GIVE(WeightCosine);
85-
GIVE_EX(make_Clamped(aValue.mDistanceFactor, { .mMax = 50.0f }), DistanceFactor);
85+
GIVE_EX(make_Clamped(aValue.mDistanceFactor, { .mMax = 50.0f }), "DistanceFactor");
8686
}
8787

8888
DESCRIBE(FrameGraph::BlurControl)
8989
{
90-
GIVE_EX(make_Clamped(aValue.mBlurRadius, {.mMin = 0, .mMax = 32 }), BlurRadius);
91-
GIVE_EX(make_Clamped(aValue.mDepthFactor, {.mMin = 0, .mMax = 100 }), DepthFactor);
92-
GIVE_EX(make_Clamped(aValue.mNormalFactor, {.mMin = 0, .mMax = 100 }), NormalFactor);
90+
GIVE_EX(make_Clamped(aValue.mBlurRadius, {.mMin = 0, .mMax = 32 }), "BlurRadius");
91+
GIVE_EX(make_Clamped(aValue.mDepthFactor, {.mMin = 0, .mMax = 100 }), "DepthFactor");
92+
GIVE_EX(make_Clamped(aValue.mNormalFactor, {.mMin = 0, .mMax = 100 }), "NormalFactor");
9393
}
9494

9595
std::string to_string(TextureStore::Name aName)

src/apps/ch11_ssao/ch11_ssao/Material.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct PhongMaterialsBlock_glsl
5656

5757
DESCRIBE(PhongMaterialsBlock_glsl)
5858
{
59-
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), count);
59+
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), "count");
6060
GIVE_EX(aValue.spanMaterials(), "materials");
6161
}
6262

@@ -79,7 +79,7 @@ DESCRIBE(PbrMaterial_glsl)
7979
GIVE(AmbientColor);
8080
GIVE(BaseColor);
8181
GIVE(Metallic);
82-
GIVE_EX((Clamped<GLfloat>{aValue.mRoughness, 0.f, 1.f}), Roughness);
82+
GIVE_EX((Clamped<GLfloat>{aValue.mRoughness, 0.f, 1.f}), "Roughness");
8383
}
8484

8585

@@ -100,7 +100,7 @@ struct PbrMaterialsBlock_glsl
100100

101101
DESCRIBE(PbrMaterialsBlock_glsl)
102102
{
103-
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), count);
103+
GIVE_EX((Clamped<GLuint>{aValue.mCount, 0, gMaxMaterials}), "count");
104104
GIVE_EX(aValue.spanMaterials(), "materials");
105105
}
106106

0 commit comments

Comments
 (0)