Skip to content

Commit c7c1b84

Browse files
authored
Merge branch 'haosulab:rt' into rt
2 parents 9abb714 + 00c2b3e commit c7c1b84

File tree

12 files changed

+37
-8
lines changed

12 files changed

+37
-8
lines changed

include/sapien/renderer/svulkan2_material.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class SVulkan2Material : public IPxrMaterial {
6565
void setNormalTexture(std::shared_ptr<IPxrTexture> texture) override;
6666
void setNormalTextureFromFilename(std::string_view filename) override;
6767
[[nodiscard]] std::shared_ptr<IPxrTexture> getNormalTexture() const override;
68+
void setTransmissionTexture(std::shared_ptr<IPxrTexture> texture) override;
69+
void setTransmissionTextureFromFilename(std::string_view filename) override;
70+
[[nodiscard]] std::shared_ptr<IPxrTexture> getTransmissionTexture() const override;
6871

6972
[[nodiscard]] std::shared_ptr<svulkan2::resource::SVMetallicMaterial> getMaterial() const {
7073
return mMaterial;

python/py_package/utils/viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def build_ik_window(self):
13411341
)
13421342

13431343
def take_screenshot(self, _):
1344-
picture = self.window.get_float_texture("Color")
1344+
picture = self.window.get_float_texture(self.target_name)
13451345
for i in range(100000000):
13461346
n = f"sapien_screenshot_{i}.png"
13471347
if os.path.exists(n):

python/pysapien_renderer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void buildRenderer(py::module &parent) {
506506
.def("set_textures", &resource::SVMetallicMaterial::setTextures,
507507
py::arg("base_color") = nullptr, py::arg("roughness") = nullptr,
508508
py::arg("normal") = nullptr, py::arg("metallic") = nullptr,
509-
py::arg("emission") = nullptr)
509+
py::arg("emission") = nullptr, py::arg("transmission") = nullptr)
510510
.def(
511511
"set_base_color",
512512
[](resource::SVMetallicMaterial &mat, py::array_t<float> color) {
@@ -515,7 +515,9 @@ void buildRenderer(py::module &parent) {
515515
py::arg("rgba"))
516516
.def("set_specular", &resource::SVMetallicMaterial::setFresnel, py::arg("specular"))
517517
.def("set_metallic", &resource::SVMetallicMaterial::setMetallic, py::arg("metallic"))
518-
.def("set_roughness", &resource::SVMetallicMaterial::setRoughness, py::arg("roughness"));
518+
.def("set_roughness", &resource::SVMetallicMaterial::setRoughness, py::arg("roughness"))
519+
.def("set_emission", &resource::SVMetallicMaterial::setRoughness, py::arg("emission"))
520+
.def("set_transmission", &resource::SVMetallicMaterial::setRoughness, py::arg("transmission"));
519521

520522
PyScene
521523
.def(

src/renderer/svulkan2_material.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ std::shared_ptr<IPxrTexture> SVulkan2Material::getMetallicTexture() const {
176176
return tex ? std::make_shared<SVulkan2Texture>(tex) : nullptr;
177177
}
178178

179+
void SVulkan2Material::setTransmissionTexture(std::shared_ptr<IPxrTexture> texture) {
180+
if (auto tex = std::dynamic_pointer_cast<SVulkan2Texture>(texture)) {
181+
mMaterial->setTransmissionTexture(tex->getTexture());
182+
} else {
183+
mMaterial->setTransmissionTexture(nullptr);
184+
}
185+
}
186+
std::shared_ptr<IPxrTexture> SVulkan2Material::getTransmissionTexture() const {
187+
auto tex = mMaterial->getTransmissionTexture();
188+
return tex ? std::make_shared<SVulkan2Texture>(tex) : nullptr;
189+
}
190+
179191
void SVulkan2Material::setEmissionTextureFromFilename(std::string_view filename) {
180192
setEmissionTexture(mParentRenderer->createTexture(filename));
181193
}
@@ -191,6 +203,9 @@ void SVulkan2Material::setMetallicTextureFromFilename(std::string_view filename)
191203
void SVulkan2Material::setRoughnessTextureFromFilename(std::string_view filename) {
192204
setRoughnessTexture(mParentRenderer->createTexture(filename));
193205
}
206+
void SVulkan2Material::setTransmissionTextureFromFilename(std::string_view filename) {
207+
setTransmissionTexture(mParentRenderer->createTexture(filename));
208+
}
194209

195210
} // namespace Renderer
196211
} // namespace sapien

vulkan_shader/ibl/gbuffer.frag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ layout(set = 2, binding = 2) uniform sampler2D roughnessTexture;
3737
layout(set = 2, binding = 3) uniform sampler2D normalTexture;
3838
layout(set = 2, binding = 4) uniform sampler2D metallicTexture;
3939
layout(set = 2, binding = 5) uniform sampler2D emissionTexture;
40+
layout(set = 2, binding = 6) uniform sampler2D transmissionTexture;
4041

4142
layout(location = 0) in vec4 inPosition;
4243
layout(location = 1) in vec4 inPrevPosition;

vulkan_shader/point/gbuffer1.frag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ layout(set = 2, binding = 2) uniform sampler2D roughnessTexture;
4545
layout(set = 2, binding = 3) uniform sampler2D normalTexture;
4646
layout(set = 2, binding = 4) uniform sampler2D metallicTexture;
4747
layout(set = 2, binding = 5) uniform sampler2D emissionTexture;
48+
layout(set = 2, binding = 6) uniform sampler2D transmissionTexture;
4849

4950
#include "../common/lights.glsl"
5051

vulkan_shader/point/gbuffer2.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ layout(set = 2, binding = 1) uniform sampler2D colorTexture;
1919
layout(set = 2, binding = 2) uniform sampler2D roughnessTexture;
2020
layout(set = 2, binding = 3) uniform sampler2D normalTexture;
2121
layout(set = 2, binding = 4) uniform sampler2D metallicTexture;
22+
layout(set = 2, binding = 5) uniform sampler2D emissionTexture;
23+
layout(set = 2, binding = 6) uniform sampler2D transmissionTexture;
2224

2325
layout(location = 0) in vec4 inPosition;
2426
layout(location = 1) in vec2 inUV;

vulkan_shader/rt/camera.rchit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ vec3 evalGGXTransmission(vec3 N, vec3 L, vec3 V, float eta, float roughness) {
238238

239239
float dotNH = clamp(dot(N, H), 1e-6, 1);
240240
float dotVH = clamp(dot(V, H), 1e-6, 1);
241-
float dotNL = dot(N, L);
241+
float dotNL = clamp(dot(N, L), 1e-6, 1);
242242
float dotNV = clamp(dot(N, V), 1e-6, 1);
243243

244244
float F = dielectricFresnel(dotVH, 1.0 / eta);
@@ -512,7 +512,7 @@ void main() {
512512
}
513513

514514
if (rnd(ray.seed) < obj.transparency) {
515-
ray.origin = worldPosition + 0.001 * ray.direction;
515+
ray.origin = worldPosition;
516516
ray.attenuation = vec3(1.0);
517517
ray.normal = worldShadingNormal;
518518
ray.albedo = baseColor;

vulkan_shader/rt/camera.rgen

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ layout(set = 0, binding = 1, rgba32f) uniform image2D outAlbedo;
1515
layout(set = 0, binding = 2, rgba32f) uniform image2D outNormal;
1616
layout(set = 0, binding = 3, rgba32ui) uniform uimage2D outSegmentation;
1717
layout(set = 0, binding = 4, rgba32f) uniform image2D outRadiance;
18+
layout(set = 0, binding = 5, rgba32f) uniform image2D outPosition;
1819

1920
layout(set = 1, binding = 0) uniform accelerationStructureEXT tlas;
2021

@@ -104,6 +105,10 @@ void main() {
104105
imageStore(outNormal, ivec2(gl_LaunchIDEXT.xy), vec4(mat3(cameraBuffer.viewMatrix) * ray.normal, 1.0));
105106
imageStore(outAlbedo, ivec2(gl_LaunchIDEXT.xy), vec4(ray.albedo, 1.0));
106107
imageStore(outSegmentation, ivec2(gl_LaunchIDEXT.xy), ray.segmentation);
108+
109+
vec4 position = cameraBuffer.viewMatrix * vec4(ray.origin, 1.0);
110+
vec4 ndc = cameraBuffer.projectionMatrix * position;
111+
imageStore(outPosition, ivec2(gl_LaunchIDEXT.xy), vec4(position.xyz, ndc.z / ndc.w));
107112
}
108113
}
109114
radiance += attenuation * ambientLight; // HACK: implement unterminated ray properly

0 commit comments

Comments
 (0)