Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions examples/15_pointlight/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ int main()
);

PointLight pointLights[5] = { // XYZ, strength, color
{{{ 150.0f, 20.0f, -5.0f}}, 0.055f, {0xFF, 0xFF, 0x1F, 0xFF}},
{{{-150.0f, 20.0f, -5.0f}}, 0.055f, {0x1F, 0xFF, 0x1F, 0xFF}},
{{{ 0.0f, 40.0f, -190.0f}}, 0.300f, {0x1F, 0x1F, 0xFF, 0xFF}},
{{{ 0.0f, 20.0f, 30.0f}}, 0.055f, {0xFF, 0x1F, 0x1F, 0xFF}},
{{{ 0.0f, 25.0f, 0.0f}}, 0.150f, {0xFF, 0x2F, 0x1F, 0xFF}},
{{{ 150.0f, 20.0f, -5.0f}}, 40.0f, {0xFF, 0xFF, 0x1F, 0xFF}},
{{{-150.0f, 20.0f, -5.0f}}, 40.0f, {0x1F, 0xFF, 0x1F, 0xFF}},
{{{ 0.0f, 40.0f, -190.0f}}, 80.0f, {0x1F, 0x1F, 0xFF, 0xFF}},
{{{ 0.0f, 20.0f, 30.0f}}, 40.0f, {0xFF, 0x1F, 0x1F, 0xFF}},
{{{ 0.0f, 25.0f, 0.0f}}, 60.0f, {0xFF, 0x2F, 0x1F, 0xFF}},
};

color_t lightColorOff = {0,0,0, 0xFF};
uint32_t currLight = 0;
uint8_t colorAmbient[4] = {20, 20, 20, 0xFF};
Expand Down Expand Up @@ -131,8 +130,8 @@ int main()

// Light controls
float moveSpeed = deltaTime * 0.75f;
light->strength += (float)joypad.cstick_x * deltaTime * 0.002f;
light->strength = fminf(1.0f, fmaxf(0.0f, light->strength));
light->strength += (float)joypad.cstick_x * deltaTime * 0.4f;
light->strength = fminf(190.0f, fmaxf(0.0f, light->strength));

light->pos.v[0] -= camDir.v[2] * (float)joypad.stick_x * -moveSpeed;
light->pos.v[2] += camDir.v[0] * (float)joypad.stick_x * -moveSpeed;
Expand All @@ -157,7 +156,7 @@ int main()

// flickering and wobble of the crystal in the center of the room
pointLights[4].pos.v[1] = 24.0f + (sinf(time*2.0f) * 3.5f);
pointLights[4].strength = 0.2f
pointLights[4].strength = 100.2f
+ (fm_sinf(time * 5.1f) * 0.015f)
+ ((fm_cosf(time * 6.2f)+1) * 0.0025f)
+ ((fm_sinf(time * 2.2f)+0.9f) * 0.01f)
Expand Down Expand Up @@ -238,7 +237,7 @@ int main()
rspq_block_run(dplDraw);

for(int i=0; i<LIGHT_COUNT; ++i) {
rdpq_set_prim_color(pointLights[i].strength <= 0.0001f ? lightColorOff : pointLights[i].color);
rdpq_set_prim_color(pointLights[i].strength <= 0.01f ? lightColorOff : pointLights[i].color);
t3d_matrix_set(&matLightFP[i * FB_COUNT + frameIdx], true);
rspq_block_run(dplLight);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/16_light_clip/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ int main()

if(currMode == MODE_LIGHT) {
t3d_light_set_ambient(colorAmbientLight);
t3d_light_set_point(1, (uint8_t[]){0xFF, 0xFF, 0xFF, 0xFF}, &lightPos, 0.125f, ignoreNormals);
t3d_light_set_point(1, (uint8_t[]){0xFF, 0xFF, 0xFF, 0xFF}, &lightPos, 50.0f, ignoreNormals);
} else {
// cutout lighting, this works by using the alpha channel of the light color
// by setting the ambient alpha to 0, only dir/point lights will affect the scene
// this can be done completely independent of the actual color values
t3d_light_set_ambient(colorAmbient);
t3d_light_set_point(1, (uint8_t[]){0, 0, 0, 0xFF}, &lightPos, 0.125f, ignoreNormals);
t3d_light_set_point(1, (uint8_t[]){0, 0, 0, 0xFF}, &lightPos, 50.0f, ignoreNormals);
}
t3d_light_set_count(2);

Expand Down
6 changes: 3 additions & 3 deletions examples/21_fresnel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int main()
// Note: point lights exactly at the camera will not work properly, so offset it slightly
t3d_light_set_point(0,
(uint8_t[4]){0x00, 0x00, 0x00, 0xFF},
&(T3DVec3){{camPos.x, camPos.y+0.1f, camPos.z+0.1f}}, 1.0f, false
&(T3DVec3){{camPos.x, camPos.y+1, camPos.z+1}}, 1000.0f, false
);
t3d_light_set_count(1);
break;
Expand All @@ -218,11 +218,11 @@ int main()
// This works since each light source is added together, and the CC inverts it
t3d_light_set_point(0,
(uint8_t[4]){0x00, 0x00, 0x00, 0xF0},
&(T3DVec3){{camPos.x+0.075f, camPos.y+0.1f, camPos.z+0.1f}}, 1.0f, false
&(T3DVec3){{camPos.x+0.075f, camPos.y+1, camPos.z+1}}, 1000.0f, false
);
t3d_light_set_point(1,
(uint8_t[4]){0x00, 0x00, 0x00, 0x90},
&(T3DVec3){{camPos.x+0.075f, camPos.y+0.1f, camPos.z+0.1f}}, 1.0f, false
&(T3DVec3){{camPos.x+0.075f, camPos.y+1, camPos.z+1}}, 1000.0f, false
);
t3d_light_set_count(2);
break;
Expand Down
4 changes: 2 additions & 2 deletions examples/24_hdr_bloom/src/actors/lightBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace Actor
pos
);

t3d_light_set_point(args.index, args.color, pos, scale * 0.042f, false);
t3d_light_set_point(args.index+1, {0,0,0,0xFF}, pos, scale * 0.03f, true);
t3d_light_set_point(args.index, args.color, pos, scale * 35.0f, false);
t3d_light_set_point(args.index+1, {0,0,0,0xFF}, pos, scale * 15.0f, true);
}

void LightBlock::draw3D(float deltaTime)
Expand Down
4 changes: 2 additions & 2 deletions examples/24_hdr_bloom/src/actors/pointGlobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ namespace Actor

float visibleFactor = ((float)lastDrawnPartCount / (float)particles.countMax);
visibleFactor = fmaxf(visibleFactor, 0.7f);
float lightStrength = fade * visibleFactor * 0.35f;
lightStrength += fm_sinf(timerFlicker*20.0f) * 0.003f;
float lightStrength = fade * visibleFactor * 200.5f;
lightStrength += fm_sinf(timerFlicker*15.0f) * 4.0f;
t3d_light_set_point(0, lightPointColor, &pos, lightStrength, false);

timer += deltaTime * 0.25f;
Expand Down
6 changes: 3 additions & 3 deletions src/t3d/rsp/rsp_tiny3d.S
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ pointLight:
ldv $v23, 0, 8, $s3 ## L:697 | ^ | ptPos:sint.xyzw = load(ptrLight, 8).xyzw;
ldv $v23, 8, 8, $s3 ## L:698 | 30 | ptPos:sint.XYZW = load(ptrLight, 8).xyzw;
andi $t7, $t7, 32767 ## L:693 | ***34 | lightSize &= 0x7FFF;
vmudm $v23, $v23, $v31.e7 ## L:700 | ^ | ptPos = ptPos:sint >> 8;
vmadn $v24, $v00, $v00 ## L:700 | 35 | ptPos = ptPos:sint >> 8;
sll $t7, $t7, 13 ## L:694 | ^ | lightSize <<= 13;
vmudm $v23, $v23, $v31.e5 ## L:700 | ^ | ptPos = ptPos:sint >> 6;
vmadn $v24, $v00, $v00 ## L:700 | 35 | ptPos = ptPos:sint >> 6;
sll $t7, $t7, 16 ## L:694 | ^ | lightSize <<= 16;
vsubc $v24, $v24, $v28.v ## L:701 | ***39 | ptPos = ptPos - vertPos;
vsub $v23, $v23, $v27.v ## L:701 | 40 | ptPos = ptPos - vertPos;
vmudl $v29, $v24, $v24.v ## L:704 | **43 | lightVertDot = ptPos * ptPos;
Expand Down
4 changes: 2 additions & 2 deletions src/t3d/rsp/rsp_tiny3d.rspl
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,13 @@ function pointLight(
}

lightSize &= 0x7FFF; // MSB is "use-normal" flag
lightSize <<= 13; // shift s16 into s16 range
lightSize <<= 16; // shift s16 into s16 range

// get light position
ptPos:sint.xyzw = load(ptrLight, 8).xyzw;
ptPos:sint.XYZW = load(ptrLight, 8).xyzw;

ptPos = ptPos:sint >> 8; // light position into 16.16
ptPos = ptPos:sint >> 6; // light position into 16.16
ptPos = ptPos - vertPos; // get distance from light to vertex

// calc. dot product and normalize distance vector
Expand Down
16 changes: 11 additions & 5 deletions src/t3d/t3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,22 @@ void t3d_light_set_point(int index, const uint8_t *color, const T3DVec3 *pos, fl
T3DVec4 posView;
t3d_mat4_mul_vec3(&posView, &currentViewport->matCamera, pos);

size *= 0.5f;
size = size * (1.0f / 0x2000);
size = fmaxf(size, 0.0f);
size = fminf(size, 0.5f);

int32_t posFP[4] = {
(int32_t)(posView.v[0] * 16.0f) & 0xFFFF,
(int32_t)(posView.v[1] * 16.0f) & 0xFFFF,
(int32_t)(posView.v[2] * 16.0f) & 0xFFFF,
(int32_t)(size * 0xFFFF) & 0xFFFF
(int32_t)(posView.v[0] * 4.0f),
(int32_t)(posView.v[1] * 4.0f),
(int32_t)(posView.v[2] * 4.0f),
(int32_t)(size * 0xFFFF)
};

for(int i=0; i<4; ++i) {
posFP[i] = CLAMP(posFP[i], -0x8000, 0x7FFF);
posFP[i] &= 0xFFFF;
}

if((posFP[3] & 0xFF) == 0)posFP[3] |= 1; // non-zero size is used as point-light detection
if(ignoreNormals)posFP[3] |= 0x8000; // ignore normals

Expand Down
7 changes: 3 additions & 4 deletions src/t3d/t3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,13 @@ void t3d_light_set_directional(int index, const uint8_t *color, const T3DVec3 *d
* The position is expected to be in world-space, and will be transformed internally.
* Before calling this function, make sure to have a viewport attached.
*
* The size argument is a normalized distance, in the range 0.0 - 1.0.
* Internally in the ucode, this maps to scaling factors in eye-space.
* So unlike 'pos', it doesn't have any concrete units.
* The size argument is roughly the maximum radius in world-space the light will cover.
* Note that due to precision limitations and the fact lighting happens per vertex, the size is not exact.
*
* @param index index (0-6)
* @param color color in RGBA8 format
* @param pos position in world-space
* @param size distance, in range 0.0 - 1.0
* @param size distance, in world-space
* @param ignoreNormals if true, the light will only check the distance, not the angle (useful for cutouts)
*/
void t3d_light_set_point(int index, const uint8_t *color, const T3DVec3 *pos, float size, bool ignoreNormals);
Expand Down
2 changes: 1 addition & 1 deletion tools/gltf_importer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OBJDIR = build
SRCDIR = src
INSTALLDIR = $(N64_INST)

OBJ = build/parser.o build/main.o build/lib/lodepng.o \
OBJ = build/parser.o build/writer.o build/main.o build/lib/lodepng.o \
build/parser/materialParser.o build/parser/boneParser.o build/parser/nodeParser.o \
build/optimizer/meshOptimizer.o \
build/optimizer/meshBVH.o \
Expand Down
24 changes: 12 additions & 12 deletions tools/gltf_importer/src/converter/animConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace {
return (uint16_t)roundf(t * 60.0f);
}

bool hasConstValue(const std::vector<Keyframe> &keyframes, bool isRotation) {
bool hasConstValue(const std::vector<T3DM::Keyframe> &keyframes, bool isRotation) {
if(!isRotation) {
float lastValue = keyframes[0].valScalar;
for(int i=1; i < keyframes.size(); ++i) {
Expand All @@ -33,16 +33,16 @@ namespace {
}

// Filters any channel that has a constant value, and is also the identity value of the specific target
bool isEmptyChannel(AnimChannelMapping &channel)
bool isEmptyChannel(T3DM::AnimChannelMapping &channel)
{
if(hasConstValue(channel.keyframes, channel.isRotation())) {
bool isIdentity = false;
const auto &kf = channel.keyframes[0];
switch(channel.targetType) {
case AnimChannelTarget::TRANSLATION : isIdentity = fabsf(kf.valScalar) < MIN_VALUE_DELTA; break;
case AnimChannelTarget::ROTATION : isIdentity = kf.valQuat.isIdentity(); break;
case AnimChannelTarget::SCALE_UNIFORM:
case AnimChannelTarget::SCALE : isIdentity = kf.valScalar == 1.0f; break;
case T3DM::AnimChannelTarget::TRANSLATION : isIdentity = fabsf(kf.valScalar) < MIN_VALUE_DELTA; break;
case T3DM::AnimChannelTarget::ROTATION : isIdentity = kf.valQuat.isIdentity(); break;
case T3DM::AnimChannelTarget::SCALE_UNIFORM:
case T3DM::AnimChannelTarget::SCALE : isIdentity = kf.valScalar == 1.0f; break;
}
//if(isIdentity)printf(" - Channel %s %d has identity value\n", channel.targetName.c_str(), channel.targetType);
return isIdentity;
Expand All @@ -54,7 +54,7 @@ namespace {
* Optimizes the keyframes of a channel.
* This will attempt to remove keyframes while staying within a certain error threshold.
*/
void optimizeChannel(AnimChannelMapping &channel, float time) {
void optimizeChannel(T3DM::AnimChannelMapping &channel, float time) {
if(channel.keyframes.size() < 2)return;
auto channelOrg = channel;
float mse = calcMSE(channel.keyframes, channelOrg.keyframes, 0, time, channel.isRotation());
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace {
}
}

void quantizeRotation(Keyframe &kf)
void quantizeRotation(T3DM::Keyframe &kf)
{
uint32_t quatQuant = Quantizer::quatTo32Bit(kf.valQuat);
if(quatQuant == 0) {
Expand All @@ -94,7 +94,7 @@ namespace {
}
}

void convertAnimation(Anim &anim, const std::unordered_map<std::string, const Bone*> &nodeMap)
void convertAnimation(T3DM::Anim &anim, const std::unordered_map<std::string, const T3DM::Bone*> &nodeMap)
{
// remove all empty channels
anim.channelMap.erase(
Expand Down Expand Up @@ -148,7 +148,7 @@ void convertAnimation(Anim &anim, const std::unordered_map<std::string, const Bo
}

// sort keyframes by time, if the time is the same, sort by channel index
std::sort(anim.keyframes.begin(), anim.keyframes.end(), [](const Keyframe &a, const Keyframe &b) {
std::sort(anim.keyframes.begin(), anim.keyframes.end(), [](const T3DM::Keyframe &a, const T3DM::Keyframe &b) {
if(a.timeNeededTicks == b.timeNeededTicks) {
if(a.timeTicks == b.timeTicks) {
return a.chanelIdx < b.chanelIdx;
Expand All @@ -162,7 +162,7 @@ void convertAnimation(Anim &anim, const std::unordered_map<std::string, const Bo
for(auto &kf : anim.keyframes)
{
auto &ch = anim.channelMap[kf.chanelIdx];
if(ch.targetType == AnimChannelTarget::ROTATION) {
if(ch.targetType == T3DM::AnimChannelTarget::ROTATION) {
quantizeRotation(kf);
} else {
kf.valQuantSize = 1;
Expand All @@ -174,7 +174,7 @@ void convertAnimation(Anim &anim, const std::unordered_map<std::string, const Bo
anim.channelCountQuat = 0;
anim.channelCountScalar = 0;
for(auto &ch : anim.channelMap) {
if(ch.targetType == AnimChannelTarget::ROTATION) {
if(ch.targetType == T3DM::AnimChannelTarget::ROTATION) {
anim.channelCountQuat++;
} else {
anim.channelCountScalar++;
Expand Down
6 changes: 3 additions & 3 deletions tools/gltf_importer/src/converter/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "../structs.h"

void convertVertex(
float modelScale, float texSizeX, float texSizeY, const VertexNorm &v, VertexT3D &vT3D,
float modelScale, float texSizeX, float texSizeY, const T3DM::VertexNorm &v, T3DM::VertexT3D &vT3D,
const Mat4 &mat, const std::vector<Mat4> &matrices, bool uvAdjust
);
ModelChunked chunkUpModel(const Model& model);
T3DM::ModelChunked chunkUpModel(const T3DM::Model& model);

void convertAnimation(Anim &anim, const std::unordered_map<std::string, const Bone*> &nodeMap);
void convertAnimation(T3DM::Anim &anim, const std::unordered_map<std::string, const T3DM::Bone*> &nodeMap);
Loading
Loading