Skip to content

Commit 111b7fa

Browse files
Merge pull request #36 from knightcrawler25/dev
Fixes
2 parents ca8f088 + 64477d3 commit 111b7fa

19 files changed

+194
-141
lines changed

src/Main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void SaveFrame(const std::string filename)
121121
int w, h;
122122
renderer->GetOutputBuffer(&data, w, h);
123123
stbi_flip_vertically_on_write(true);
124-
stbi_write_bmp(filename.c_str(), w, h, 3, data);
124+
stbi_write_png(filename.c_str(), w, h, 3, data, w*3);
125125
delete data;
126126
}
127127

@@ -276,7 +276,7 @@ void MainLoop(void* arg)
276276

277277
if (ImGui::Button("Save Screenshot"))
278278
{
279-
SaveFrame("./img_" + to_string(renderer->GetSampleCount()) + ".jpg");
279+
SaveFrame("./img_" + to_string(renderer->GetSampleCount()) + ".png");
280280
}
281281

282282
std::vector<const char*> scenes;
@@ -378,13 +378,14 @@ void MainLoop(void* arg)
378378
objectPropChanged |= ImGui::SliderFloat("Specular", &scene->materials[scene->meshInstances[selectedInstance].materialID].specular, 0.0f, 1.0f);
379379
objectPropChanged |= ImGui::SliderFloat("SpecularTint", &scene->materials[scene->meshInstances[selectedInstance].materialID].specularTint, 0.0f, 1.0f);
380380
objectPropChanged |= ImGui::SliderFloat("Subsurface", &scene->materials[scene->meshInstances[selectedInstance].materialID].subsurface, 0.0f, 1.0f);
381-
objectPropChanged |= ImGui::SliderFloat("Anisotropic", &scene->materials[scene->meshInstances[selectedInstance].materialID].anisotropic, 0.0f, 1.0f);
381+
//objectPropChanged |= ImGui::SliderFloat("Anisotropic", &scene->materials[scene->meshInstances[selectedInstance].materialID].anisotropic, 0.0f, 1.0f);
382382
objectPropChanged |= ImGui::SliderFloat("Sheen", &scene->materials[scene->meshInstances[selectedInstance].materialID].sheen, 0.0f, 1.0f);
383383
objectPropChanged |= ImGui::SliderFloat("SheenTint", &scene->materials[scene->meshInstances[selectedInstance].materialID].sheenTint, 0.0f, 1.0f);
384384
objectPropChanged |= ImGui::SliderFloat("Clearcoat", &scene->materials[scene->meshInstances[selectedInstance].materialID].clearcoat, 0.0f, 1.0f);
385-
objectPropChanged |= ImGui::SliderFloat("clearcoatRoughness", &scene->materials[scene->meshInstances[selectedInstance].materialID].clearcoatRoughness, 0.001f, 1.0f);
385+
objectPropChanged |= ImGui::SliderFloat("clearcoatGloss", &scene->materials[scene->meshInstances[selectedInstance].materialID].clearcoatGloss, 0.0f, 1.0f);
386386
objectPropChanged |= ImGui::SliderFloat("Transmission", &scene->materials[scene->meshInstances[selectedInstance].materialID].transmission, 0.0f, 1.0f);
387387
objectPropChanged |= ImGui::SliderFloat("Ior", &scene->materials[scene->meshInstances[selectedInstance].materialID].ior, 1.001f, 2.0f);
388+
objectPropChanged |= ImGui::SliderFloat("atDistance", &scene->materials[scene->meshInstances[selectedInstance].materialID].atDistance, 0.05f, 10.0f);
388389
objectPropChanged |= ImGui::ColorEdit3("Extinction", (float*)extinction, 0);
389390

390391
// Transforms Properties

src/core/Material.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,20 @@ namespace GLSLPT
4848
sheen = 0.0f;
4949
sheenTint = 0.0f;
5050
clearcoat = 0.0f;
51-
clearcoatRoughness = 0.0f;
51+
clearcoatGloss = 0.0f;
52+
53+
transmission = 0.0f;
54+
ior = 1.45f;
55+
atDistance = 1.0f;
56+
padding1 = 0.0f;
5257

53-
transmission = 0.0f;
54-
ior = 1.45f;
5558
extinction = Vec3(1.0f, 1.0f, 1.0f);
59+
padding2 = 0.0f;
5660

57-
albedoTexID = -1.0f;
58-
metallicRoughnessTexID = -1.0f;
59-
normalmapTexID = -1.0f;
61+
albedoTexID = -1.0f;
62+
metallicRoughnessTexID = -1.0f;
63+
normalmapTexID = -1.0f;
64+
padding3 = 0.0f;
6065
};
6166

6267
Vec3 albedo;
@@ -73,14 +78,19 @@ namespace GLSLPT
7378
float sheen;
7479
float sheenTint;
7580
float clearcoat;
76-
float clearcoatRoughness;
81+
float clearcoatGloss;
7782

7883
float transmission;
7984
float ior;
85+
float atDistance;
86+
float padding1;
87+
8088
Vec3 extinction;
89+
float padding2;
8190

8291
float albedoTexID;
8392
float metallicRoughnessTexID;
8493
float normalmapTexID;
94+
float padding3;
8595
};
8696
}

src/loaders/Loader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ namespace GLSLPT
108108
sscanf(line, " sheen %f", &material.sheen);
109109
sscanf(line, " sheenTint %f", &material.sheenTint);
110110
sscanf(line, " clearcoat %f", &material.clearcoat);
111-
sscanf(line, " clearcoatRoughness %f", &material.clearcoatRoughness);
111+
sscanf(line, " clearcoatGloss %f", &material.clearcoatGloss);
112112
sscanf(line, " transmission %f", &material.transmission);
113113
sscanf(line, " ior %f", &material.ior);
114114
sscanf(line, " extinction %f %f %f", &material.extinction.x, &material.extinction.y, &material.extinction.z);
115+
sscanf(line, " atDistance %f", &material.atDistance);
115116
sscanf(line, " albedoTexture %s", albedoTexName);
116117
sscanf(line, " metallicRoughnessTexture %s", metallicRoughnessTexName);
117118
sscanf(line, " normalTexture %s", normalTexName);

src/shaders/common/anyhit.glsl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,45 @@
2626
bool AnyHit(Ray r, float maxDist)
2727
//-----------------------------------------------------------------------
2828
{
29+
30+
#ifdef LIGHTS
31+
// Intersect Emitters
32+
for (int i = 0; i < numOfLights; i++)
33+
{
34+
// Fetch light Data
35+
vec3 position = texelFetch(lightsTex, ivec2(i * 5 + 0, 0), 0).xyz;
36+
vec3 emission = texelFetch(lightsTex, ivec2(i * 5 + 1, 0), 0).xyz;
37+
vec3 u = texelFetch(lightsTex, ivec2(i * 5 + 2, 0), 0).xyz;
38+
vec3 v = texelFetch(lightsTex, ivec2(i * 5 + 3, 0), 0).xyz;
39+
vec3 params = texelFetch(lightsTex, ivec2(i * 5 + 4, 0), 0).xyz;
40+
float radius = params.x;
41+
float area = params.y;
42+
float type = params.z;
43+
44+
// Intersect rectangular area light
45+
if (type == QUAD_LIGHT)
46+
{
47+
vec3 normal = normalize(cross(u, v));
48+
vec4 plane = vec4(normal, dot(normal, position));
49+
u *= 1.0f / dot(u, u);
50+
v *= 1.0f / dot(v, v);
51+
52+
float d = RectIntersect(position, u, v, plane, r);
53+
if (d > 0.0 && d < maxDist)
54+
return true;
55+
}
56+
57+
// Intersect spherical area light
58+
if (type == SPHERE_LIGHT)
59+
{
60+
float d = SphereIntersect(radius, position, r);
61+
if (d > 0.0 && d < maxDist)
62+
return true;
63+
}
64+
}
65+
#endif
66+
67+
// Intersect BVH and tris
2968
int stack[64];
3069
int ptr = 0;
3170
stack[ptr++] = -1;

src/shaders/common/closest_hit.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ float ClosestHit(Ray r, inout State state, inout LightSampleRec lightSampleRec)
4343
float area = params.y;
4444
float type = params.z;
4545

46-
// Rectangular Area Light
46+
// Intersect rectangular area light
4747
if (type == 0.)
4848
{
4949
vec3 normal = normalize(cross(u, v));
@@ -67,7 +67,7 @@ float ClosestHit(Ray r, inout State state, inout LightSampleRec lightSampleRec)
6767
}
6868
}
6969

70-
// Spherical Area Light
70+
// Intersect spherical area light
7171
if (type == 1.)
7272
{
7373
d = SphereIntersect(radius, position, r);
@@ -85,6 +85,7 @@ float ClosestHit(Ray r, inout State state, inout LightSampleRec lightSampleRec)
8585
}
8686
#endif
8787

88+
// Intersect BVH and tris
8889
int stack[64];
8990
int ptr = 0;
9091
stack[ptr++] = -1;

0 commit comments

Comments
 (0)