Skip to content

Commit c4ba7e7

Browse files
committed
bones in skins are being loaded in the right order now. I think it's working :D. Also fixed a ton of shader issues that cause GL to crash.
1 parent de30c64 commit c4ba7e7

File tree

6 files changed

+48
-39
lines changed

6 files changed

+48
-39
lines changed

data/effects/color_conversion.effect

+3-9
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,14 @@ float4 RGBtoYUV(float4 rgba, float3x3 yuv) {
3434
}
3535

3636
float4 RGBToYUVAPass(VertDataOut v_in) : TARGET {
37-
const float3x3 mYUV709n = { // Normalized
37+
const float3x3 mYUV709n = float3x3( // Normalized
3838
0.2126, 0.7152, 0.0722,
3939
-0.1145721060573399, -0.3854278939426601, 0.5,
4040
0.5, -0.4541529083058166, -0.0458470916941834
41-
};
41+
);
4242
return RGBtoYUV(image.Sample(primarySampler, v_in.uv), mYUV709n);
4343
}
44-
/*
45-
float4 RGBToYPass(VertDataOut v_in) : TARGET {
46-
float ycbcr = YUV709fromRGB(image.Sample(primarySampler, v_in.uv)); // <--- we seem to be missing this
47-
return float4(ycbcr.r, 0, 0, 0);
48-
}
49-
*/
44+
5045

5146
technique RGBToYUV {
5247
pass {
@@ -59,6 +54,5 @@ technique RGBToLuma {
5954
pass {
6055
vertex_shader = VSDefault(v_in);
6156
pixel_shader = RGBToYUVAPass(v_in);
62-
// pixel_shader = RGBToYPass(v_in);
6357
}
6458
}

data/effects/phong.effect

+22-22
Original file line numberDiff line numberDiff line change
@@ -233,63 +233,63 @@ VertDataOut VSPhong(VertDataIn v_in)
233233

234234
int i, bi, nvb;
235235
float w;
236-
float3 r = {0.0, 0.0, 0.0};
236+
float3 r = float3(0.0, 0.0, 0.0);
237237
float4 vinpos = float4(v_in.pos.xyz, 1.0);
238238

239239
if (numBones > 0) {
240-
nvb = v_in.boneinfo1.x;
240+
nvb = int(v_in.boneinfo1.x);
241241
for(i = 0; i < nvb; i++) {
242242
switch(i) {
243243
case 0:
244-
bi = v_in.boneinfo1.z;
244+
bi = int(v_in.boneinfo1.z);
245245
w = v_in.boneinfo1.w;
246246
break;
247247
case 1:
248-
bi = v_in.boneinfo2.x;
248+
bi = int(v_in.boneinfo2.x);
249249
w = v_in.boneinfo2.y;
250250
break;
251251
case 2:
252-
bi = v_in.boneinfo2.z;
252+
bi = int(v_in.boneinfo2.z);
253253
w = v_in.boneinfo2.w;
254254
break;
255255
case 3:
256-
bi = v_in.boneinfo3.x;
256+
bi = int(v_in.boneinfo3.x);
257257
w = v_in.boneinfo3.y;
258258
break;
259259
case 4:
260-
bi = v_in.boneinfo3.z;
260+
bi = int(v_in.boneinfo3.z);
261261
w = v_in.boneinfo3.w;
262262
break;
263263
case 5:
264-
bi = v_in.boneinfo4.x;
264+
bi = int(v_in.boneinfo4.x);
265265
w = v_in.boneinfo4.y;
266266
break;
267267
case 6:
268-
bi = v_in.boneinfo4.z;
268+
bi = int(v_in.boneinfo4.z);
269269
w = v_in.boneinfo4.w;
270270
break;
271271
case 7:
272-
bi = v_in.boneinfo5.x;
272+
bi = int(v_in.boneinfo5.x);
273273
w = v_in.boneinfo5.y;
274274
break;
275275
case 8:
276-
bi = v_in.boneinfo5.z;
276+
bi = int(v_in.boneinfo5.z);
277277
w = v_in.boneinfo5.w;
278278
break;
279279
case 9:
280-
bi = v_in.boneinfo6.x;
280+
bi = int(v_in.boneinfo6.x);
281281
w = v_in.boneinfo6.y;
282282
break;
283283
case 10:
284-
bi = v_in.boneinfo6.z;
284+
bi = int(v_in.boneinfo6.z);
285285
w = v_in.boneinfo6.w;
286286
break;
287287
case 11:
288-
bi = v_in.boneinfo7.x;
288+
bi = int(v_in.boneinfo7.x);
289289
w = v_in.boneinfo7.y;
290290
break;
291291
case 12:
292-
bi = v_in.boneinfo7.z;
292+
bi = int(v_in.boneinfo7.z);
293293
w = v_in.boneinfo7.w;
294294
break;
295295
}
@@ -350,10 +350,10 @@ float4 PSPhong(VertDataOut v_in) : TARGET
350350

351351
// normal
352352
float3 normal = normalize(v_in.norm);
353-
if (normalMap) {
353+
if (normalMap != 0) {
354354
float3 tangent = normalize(v_in.tangent);
355355
float3 bitangent = normalize(v_in.bitangent);
356-
float3x3 TBN = { tangent, bitangent, normal };
356+
float3x3 TBN = float3x3( tangent, bitangent, normal );
357357

358358
normal = normalTex.Sample(textureSampler, v_in.uv).xyz * 2.0 - 1.0;
359359
normal = normalize(mul(normal, TBN));
@@ -366,17 +366,17 @@ float4 PSPhong(VertDataOut v_in) : TARGET
366366
float4 emmColor = emissiveColor;
367367

368368
// texture maps
369-
if (ambientMap)
369+
if (ambientMap != 0)
370370
ambColor = ambientTex.Sample(textureSampler, v_in.uv);
371-
if (diffuseMap)
371+
if (diffuseMap != 0)
372372
dffColor = diffuseTex.Sample(textureSampler, v_in.uv);
373-
if (specularMap)
373+
if (specularMap != 0)
374374
spcColor = specularTex.Sample(textureSampler, v_in.uv);
375-
if (emissiveMap)
375+
if (emissiveMap != 0)
376376
emmColor = emissiveTex.Sample(textureSampler, v_in.uv);
377377

378378
// reflection map trumps diffuse
379-
if (reflectMap) {
379+
if (reflectMap != 0) {
380380
float3 r = reflect(normalize(-vpos), normal);
381381
float m = 2.0 * sqrt( pow( r.x, 2.0 ) + pow( r.y, 2.0 ) + pow( r.z + 1.0, 2.0 ) );
382382
float2 vN = r.xy / m + 0.5;

gs-effect.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ GS::Effect::Effect(std::string file) {
3030
obs_enter_graphics();
3131
char* errorMessage = nullptr;
3232
m_effect = gs_effect_create_from_file(file.c_str(), &errorMessage);
33-
if (!m_effect || errorMessage) {
33+
if (!m_effect || errorMessage) {
3434
std::string error(errorMessage);
3535
bfree((void*)errorMessage);
36-
obs_leave_graphics();
37-
throw std::runtime_error(error);
38-
}
36+
obs_leave_graphics();
37+
throw std::runtime_error(error);
38+
}
3939
obs_leave_graphics();
4040
}
4141

mask-resource-skinned-model.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,24 @@ Mask::Resource::SkinnedModel::SkinnedModel(Mask::MaskData* parent, std::string n
8686
PLOG_ERROR("Bad bones section in '%s'.", name.c_str());
8787
throw std::logic_error("Skinned Model has bad bones section.");
8888
}
89+
int numBones = 0;
90+
for (obs_data_item_t* itm = obs_data_first(bonesData); itm; obs_data_item_next(&itm)) {
91+
numBones++;
92+
}
93+
94+
m_bones.resize(numBones);
8995
for (obs_data_item_t* itm = obs_data_first(bonesData); itm; obs_data_item_next(&itm)) {
9096
obs_data_t* boneData = obs_data_item_get_obj(itm);
9197

98+
// use string key as index into array
99+
std::string nn = obs_data_item_get_name(itm);
100+
int boneIndex = atoi(nn.c_str());
101+
Bone& bone = m_bones[boneIndex];
102+
92103
if (!obs_data_has_user_value(boneData, S_NAME)) {
93104
PLOG_ERROR("Skinned Model '%s' bone has no name.", name.c_str());
94105
throw std::logic_error("Skinned Model has a bone with no name.");
95106
}
96-
Mask::Resource::SkinnedModel::SkinnedModel::Bone bone;
97107

98108
std::string partName = obs_data_get_string(boneData, S_NAME);
99109
bone.part = parent->GetPart(partName);
@@ -122,8 +132,6 @@ Mask::Resource::SkinnedModel::SkinnedModel(Mask::MaskData* parent, std::string n
122132
position.x, position.y, position.z);
123133

124134
matrix4_identity(&bone.global);
125-
126-
m_bones.emplace_back(bone);
127135
}
128136

129137
// Skins list

tools/MaskMaker/args.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@
2020
#include "stdafx.h"
2121
#include "args.h"
2222

23+
// STB : single-file public domain (or MIT licensed) libraries for C/C++
24+
// https://github.com/nothings/stb
2325
// you must define these for stb calls to work
26+
// - enable image library and resizing library
2427
#define STB_IMAGE_IMPLEMENTATION
2528
#define STB_IMAGE_RESIZE_IMPLEMENTATION
2629
#include "stb_image.h"
2730
#include "stb_image_resize.h"
2831

32+
// AVIR : Advanced image resizer library
33+
// https://github.com/avaneev/avir
34+
// (in stdafx.h)
35+
// - used to generate nice color-corrected super-sampled mipmaps
36+
2937
using namespace std;
3038

3139
Args::Args(int argc, char** argv)

tools/MaskMaker/command_import.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ struct VtxToBone {
281281
struct Vtx {
282282
int index;
283283
std::vector<VtxToBone> bones;
284-
std::vector<int> tris; // indices into mesh faces list
285284
};
286285

287286
struct Tri {

0 commit comments

Comments
 (0)