Skip to content

Commit

Permalink
[hdx] Show DomeLights as a skydome
Browse files Browse the repository at this point in the history
Creating the SkydomeTask to render the domeLight texture as a skydome. This additional task is added to
the _renderTaskIds as the first task in the HdxTaskController so that the AOVs are properly cleared.

Fixes #1385

(Internal change: 2182199)
  • Loading branch information
klucknav authored and pixar-oss committed Aug 12, 2021
1 parent e855e68 commit a673b8c
Show file tree
Hide file tree
Showing 18 changed files with 550 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pxr/imaging/hdx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pxr_library(hdx
selectionTracker
shadowTask
simpleLightTask
skydomeTask
task
taskController
tokens
Expand Down Expand Up @@ -95,6 +96,7 @@ pxr_library(hdx
shaders/renderPassOitVolumeShader.glslfx
shaders/renderPassShadowShader.glslfx
shaders/selection.glslfx
shaders/skydome.glslfx
shaders/visualize.glslfx
textures/StinsonBeach.exr

Expand Down
30 changes: 26 additions & 4 deletions pxr/imaging/hdx/fullscreenShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,21 @@ HdxFullscreenShader::Draw(
const GfVec4i vp(0, 0, dimensions[0], dimensions[1]);

const bool depthWrite(depthDst);
_Draw(_textures, colorDst, depthDst, vp, depthWrite);
_Draw(_textures, colorDst, HgiTextureHandle(), depthDst, HgiTextureHandle(),
vp, depthWrite);
}

void
HdxFullscreenShader::Draw(
HgiTextureHandle const& colorDst,
HgiTextureHandle const& colorResolveDst,
HgiTextureHandle const& depthDst,
HgiTextureHandle const& depthResolveDst,
GfVec4i const& viewport)
{
const bool depthWrite(depthDst);
_Draw(_textures, colorDst, colorResolveDst, depthDst, depthResolveDst,
viewport, depthWrite);
}

void
Expand All @@ -592,7 +606,9 @@ void
HdxFullscreenShader::_Draw(
TextureMap const& textures,
HgiTextureHandle const& colorDst,
HgiTextureHandle const& colorResolveDst,
HgiTextureHandle const& depthDst,
HgiTextureHandle const& depthResolveDst,
GfVec4i const &viewport,
bool writeDepth)
{
Expand Down Expand Up @@ -642,27 +658,33 @@ HdxFullscreenShader::_Draw(
_CreateBufferResources();
}

// create a default texture sampler (first time)
// Create a default texture sampler (first time)
_CreateSampler();

// Create or update the resource bindings (textures may have changed)
_CreateResourceBindings(textures);

// create pipeline (first time)
// Create pipeline (first time)
_CreatePipeline(colorDst, depthDst, writeDepth);

// Prepare graphics cmds.
HgiGraphicsCmdsDesc gfxDesc;

if (colorDst) {
gfxDesc.colorAttachmentDescs.push_back(_attachment0);
gfxDesc.colorTextures.push_back(colorDst);
}
if (colorResolveDst) {
gfxDesc.colorResolveTextures.push_back(colorResolveDst);
}

if (depthDst) {
gfxDesc.depthAttachmentDesc = _depthAttachment;
gfxDesc.depthTexture = depthDst;
}
if (depthResolveDst) {
gfxDesc.depthResolveTexture = depthResolveDst;
}

// Begin rendering
HgiGraphicsCmdsUniquePtr gfxCmds = _hgi->CreateGraphicsCmds(gfxDesc);
Expand Down
20 changes: 15 additions & 5 deletions pxr/imaging/hdx/fullscreenShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ class HdxFullscreenShader
void Draw(HgiTextureHandle const& colorDst,
HgiTextureHandle const& depthDst);

HDX_API
void Draw(HgiTextureHandle const& colorDst,
HgiTextureHandle const& colorResolveDst,
HgiTextureHandle const& depthDst,
HgiTextureHandle const& depthResolveDst,
GfVec4i const& viewport);

private:
HdxFullscreenShader() = delete;

Expand Down Expand Up @@ -157,11 +164,14 @@ class HdxFullscreenShader
bool _CreateSampler();

// Internal draw method
void _Draw(TextureMap const& textures,
HgiTextureHandle const& colorDst,
HgiTextureHandle const& depthDst,
GfVec4i const &viewport,
bool depthWrite);
void _Draw(
TextureMap const& textures,
HgiTextureHandle const& colorDst,
HgiTextureHandle const& colorResolveDst,
HgiTextureHandle const& depthDst,
HgiTextureHandle const& depthResolveDst,
GfVec4i const &viewport,
bool depthWrite);

static HgiShaderFunctionDesc GetFullScreenVertexDesc();

Expand Down
7 changes: 7 additions & 0 deletions pxr/imaging/hdx/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ HdxPackageOutlineShader()
return shader;
}

TfToken
HdxPackageSkydomeShader()
{
static TfToken shader = _GetShaderPath("skydome.glslfx");
return shader;
}

TfToken
HdxPackageDefaultDomeLightTexture()
{
Expand Down
1 change: 1 addition & 0 deletions pxr/imaging/hdx/package.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TfToken HdxPackageRenderPassOitOpaqueShader();
TfToken HdxPackageRenderPassOitVolumeShader();
TfToken HdxPackageOitResolveImageShader();
TfToken HdxPackageOutlineShader();
TfToken HdxPackageSkydomeShader();

TfToken HdxPackageDefaultDomeLightTexture();

Expand Down
84 changes: 84 additions & 0 deletions pxr/imaging/hdx/shaders/skydome.glslfx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- glslfx version 0.1

//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//

-- configuration
{
"techniques": {
"default": {
"SkydomeFragment": {
"source": [ "Skydome.Fragment" ]
}
}
}
}

-- glsl Skydome.Fragment

const float PI = 3.1415926535898;
const float farPlane = 1.0;

float wrapSampleValue(float value)
{
if (value < 0.0) {
value += 1.0;
}
else if (value > 1.0) {
value -= 1.0;
}
return value;
}

// from PreviewSurface.glslfx
vec2 projectToLatLong(vec3 sample3D)
{
// project spherical coord onto latitude-longitude map with
// latitude: +y == pi/2 and longitude: +z == 0, +x == pi/2
float x = (atan(sample3D.z, sample3D.x) + 0.5 * PI) / (2.0 * PI);
float y = acos(sample3D.y) / PI;

return vec2(wrapSampleValue(x), wrapSampleValue(y));
}


void main(void)
{
// Transform the UV coordinates into NDC space and place at the far plane
// (z = 1) before transforming into view space.
vec2 uvOut_ndc = (uvOut * vec2(2.0)) - vec2(1.0);
vec4 uvOut_view = invProjMatrix * vec4(uvOut_ndc, farPlane, 1.0);

// Normalize to use as the initial sampleDirection
vec3 sampleDirection = normalize(uvOut_view.xyz);

// Apply the camera rotation and lightTransform to the sampleDirection
sampleDirection =
( lightTransform * viewToWorld * vec4(sampleDirection, 0.0) ).xyz;

// Sample Skydome Texture with the sampleDirection
vec2 sampleCoord = projectToLatLong(sampleDirection);
hd_FragColor = vec4(HdGet_skydomeTexture(sampleCoord).xyz, 0.0);
gl_FragDepth = farPlane;
}
Loading

0 comments on commit a673b8c

Please sign in to comment.