Skip to content

Commit

Permalink
[hdEmbree] add pxrPbrt/pbrUtils.h
Browse files Browse the repository at this point in the history
A few small utility functions from pbrt-v4
  • Loading branch information
pmolodo committed Jul 31, 2024
1 parent 0cbce3f commit bc82612
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
17 changes: 17 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,23 @@ Redistributions in binary form must reproduce the above copyright notice, this l

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

============================================================
pbrt (sampling functions in hdEmbree/pxrPbrt/pbrUtils.h)
============================================================

Copyright(c) 1998-2020 Matt Pharr, Wenzel Jakob, and Greg Humphreys.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

============================================================
Draco
Expand Down
52 changes: 52 additions & 0 deletions pxr/imaging/plugin/hdEmbree/pxrPbrt/pbrtUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// pbrt is Copyright(c) 1998-2020 Matt Pharr, Wenzel Jakob, and Greg Humphreys.
// The pbrt source code is licensed under the Apache License, Version 2.0.
// SPDX: Apache-2.0

#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_PBRT_UTILS_H
#define PXR_IMAGING_PLUGIN_HD_EMBREE_PBRT_UTILS_H

#include "pxr/pxr.h"

#include "pxr/base/arch/math.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/vec3f.h"

PXR_NAMESPACE_OPEN_SCOPE

namespace pxr_pbrt {

template <typename T>
constexpr T pi = static_cast<T>(M_PI);

// Ported from PBRT
inline GfVec3f
SphericalDirection(float sinTheta, float cosTheta, float phi)
{
return GfVec3f(GfClamp(sinTheta, -1.0f, 1.0f) * GfCos(phi),
GfClamp(sinTheta, -1.0f, 1.0f) * GfSin(phi),
GfClamp(cosTheta, -1.0f, 1.0f));
}

// Ported from PBRT
inline GfVec3f
SampleUniformCone(GfVec2f const& u, float angle)
{
float cosAngle = GfCos(angle);
float cosTheta = (1.0f - u[0]) + u[0] * cosAngle;
float sinTheta = GfSqrt(GfMax(0.0f, 1.0f - cosTheta*cosTheta));
float phi = u[1] * 2.0f * pi<float>;
return SphericalDirection(sinTheta, cosTheta, phi);
}

// Ported from PBRT
inline float
InvUniformConePDF(float angle)
{
return 2.0f * pi<float> * (1.0f - GfCos(angle));
}

} // namespace pxr_pbrt

PXR_NAMESPACE_CLOSE_SCOPE

#endif // PXR_IMAGING_PLUGIN_HD_EMBREE_PBRT_UTILS_H

0 comments on commit bc82612

Please sign in to comment.