Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Aug 29, 2024
1 parent 0c69fb1 commit 8431da2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion zeno/include/zeno/types/CurveType.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static unsigned int CurveDegree(zeno::CurveType type) {
}

static std::string CurveTypeDefaultString() {
auto name = magic_enum::enum_name(CurveType::CUBIC_BSPLINE);
auto name = magic_enum::enum_name(CurveType::LINEAR);
return std::string(name);
}

Expand Down
3 changes: 2 additions & 1 deletion zenovis/xinxinoptix/hair/Hair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ std::vector<uint> Hair::segments(zeno::CurveType curveType) const
std::vector<uint> segments;
// loop to one before end, as last strand value is the "past last valid vertex"
// index
auto degree = CurveDegree(curveType);
for( auto strand = m_strands.begin(); strand != m_strands.end() - 1; ++strand )
{
const int start = *( strand ); // first vertex in first segment
const int end = *( strand + 1 ) - CurveDegree(curveType); // second vertex of last segment
const int end = *( strand + 1 ) - degree; // second vertex of last segment
for( int i = start; i < end; ++i )
{
segments.push_back( i );
Expand Down
19 changes: 14 additions & 5 deletions zenovis/xinxinoptix/hair/optixHair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void HairState::makeCurveGroupGAS(OptixDeviceContext context,
for( auto strand = strands.begin(); strand != strands.end() - 1; ++strand ) {
const int end = *( strand + 1 ) - 1;

int degree = CurveDegree(curveType);
auto degree = CurveDegree(curveType);
if (zeno::CurveType::CATROM == curveType ) {
degree -= 1;
}
Expand All @@ -79,10 +79,11 @@ void HairState::makeCurveGroupGAS(OptixDeviceContext context,
std::vector<uint> segments;
// loop to one before end, as last strand value is the "past last valid vertex"
// index
auto degree = CurveDegree(curveType);
for( auto strand = m_strands.begin(); strand != m_strands.end() - 1; ++strand )
{
const int start = *( strand ); // first vertex in first segment
const int end = *( strand + 1 ) - CurveDegree(curveType); // second vertex of last segment
const int end = *( strand + 1 ) - degree; // second vertex of last segment
for( int i = start; i < end; ++i )
{
segments.push_back( i );
Expand Down Expand Up @@ -183,10 +184,12 @@ void HairState::makeHairGAS(OptixDeviceContext context)
std::vector<float2> HairState::strandU(zeno::CurveType curveType, const std::vector<uint>& m_strands)
{
std::vector<float2> strand_u;
auto degree = CurveDegree(curveType);

for( auto strand = m_strands.begin(); strand != m_strands.end() - 1; ++strand )
{
const int start = *( strand );
const int end = *( strand + 1 ) - CurveDegree(curveType);
const int end = *( strand + 1 ) - degree;
const int segments = end - start; // number of strand's segments
const float scale = 1.0f / segments;
for( int i = 0; i < segments; ++i )
Expand All @@ -202,11 +205,14 @@ std::vector<uint2> HairState::strandInfo(zeno::CurveType curveType, const std::v
{
std::vector<uint2> strandInfo;
unsigned int firstPrimitiveIndex = 0;

auto degree = CurveDegree(curveType);

for( auto strand = m_strands.begin(); strand != m_strands.end() - 1; ++strand )
{
uint2 info;
info.x = firstPrimitiveIndex; // strand's start index
info.y = *( strand + 1 ) - *(strand)-CurveDegree(curveType); // number of segments in strand
info.y = *( strand + 1 ) - *(strand) - degree; // number of segments in strand
firstPrimitiveIndex += info.y; // increment with number of primitives/segments in strand
strandInfo.push_back( info );
}
Expand All @@ -217,10 +223,13 @@ std::vector<uint> HairState::strandIndices(zeno::CurveType curveType, const std:
{
std::vector<uint> strandIndices;
int strandIndex = 0;

auto degree = CurveDegree(curveType);

for( auto strand = m_strands.begin(); strand != m_strands.end() - 1; ++strand )
{
const int start = *( strand );
const int end = *( strand + 1 ) - CurveDegree(curveType);
const int end = *( strand + 1 ) - degree;
for( auto segment = start; segment != end; ++segment )
{
strandIndices.push_back( strandIndex );
Expand Down
21 changes: 7 additions & 14 deletions zenovis/xinxinoptix/optixSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ void buildUniformedSphereGAS(const OptixDeviceContext& context, OptixTraversabl
accel_options.buildFlags = OPTIX_BUILD_FLAG_ALLOW_COMPACTION |
OPTIX_BUILD_FLAG_ALLOW_RANDOM_VERTEX_ACCESS |
OPTIX_BUILD_FLAG_ALLOW_RANDOM_INSTANCE_ACCESS;

float3 sphereVertex = make_float3( 0.f, 0.f, 0.f );
float sphereRadius = 0.5f;

CUdeviceptr d_vertex_buffer{};
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>( &d_vertex_buffer ), sizeof( float3 ) ) );
CUDA_CHECK( cudaMemcpy( reinterpret_cast<void*>( d_vertex_buffer ), &sphereVertex,
sizeof( float3 ), cudaMemcpyHostToDevice ) );
float4 sphereVertex = make_float4(0, 0, 0, 1);

CUdeviceptr d_radius_buffer{};
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>( &d_radius_buffer ), sizeof( float ) ) );
CUDA_CHECK( cudaMemcpy( reinterpret_cast<void*>( d_radius_buffer ), &sphereRadius, sizeof( float ),
cudaMemcpyHostToDevice ) );
raii<CUdeviceptr> d_vertex_buffer {};
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>( &d_vertex_buffer.handle ), sizeof( float4) ) );
CUDA_CHECK( cudaMemcpy( reinterpret_cast<void*>( d_vertex_buffer.handle ), &sphereVertex,
sizeof( float4 ), cudaMemcpyHostToDevice ) );

CUdeviceptr d_radius_buffer = (CUdeviceptr) ((char*)d_vertex_buffer.handle + sizeof(float3));

OptixBuildInput sphere_input{};

Expand All @@ -64,9 +60,6 @@ void buildUniformedSphereGAS(const OptixDeviceContext& context, OptixTraversabl
sphere_input.sphereArray.numSbtRecords = 1;

buildXAS(context, accel_options, sphere_input, d_gas_output_buffer, gas_handle);

CUDA_CHECK( cudaFree( (void*)d_vertex_buffer ) );
CUDA_CHECK( cudaFree( (void*)d_radius_buffer ) );
}

void buildInstancedSpheresGAS(const OptixDeviceContext &context, std::vector<std::shared_ptr<SphereInstanceAgent>>& agentList) {
Expand Down

0 comments on commit 8431da2

Please sign in to comment.