Skip to content

Commit

Permalink
add objectID to hitpoint struct, add objectID textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Theverat committed Oct 1, 2018
1 parent b52b148 commit fa1b6c2
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/slg/bsdf/hitpoint.h
Expand Up @@ -53,6 +53,7 @@ typedef struct {
// computation and scene default world volume) // computation and scene default world volume)
const Volume *interiorVolume, *exteriorVolume; const Volume *interiorVolume, *exteriorVolume;
bool fromLight, intoObject; bool fromLight, intoObject;
u_int objectID;


luxrays::Frame GetFrame() const { return luxrays::Frame(dpdu, dpdv, shadeN); } luxrays::Frame GetFrame() const { return luxrays::Frame(dpdu, dpdv, shadeN); }
} HitPoint; } HitPoint;
Expand Down
88 changes: 88 additions & 0 deletions include/slg/textures/object_id.h
@@ -0,0 +1,88 @@
/***************************************************************************
* Copyright 1998-2018 by authors (see AUTHORS.txt) *
* *
* This file is part of LuxCoreRender. *
* *
* 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. *
***************************************************************************/

#ifndef _SLG_OBJECT_ID_H
#define _SLG_OBJECT_ID_H

#include "slg/textures/texture.h"

namespace slg {

//------------------------------------------------------------------------------
// ObjectID texture
//------------------------------------------------------------------------------

class ObjectIDTexture : public Texture {
public:
ObjectIDTexture() { }
virtual ~ObjectIDTexture() { }

virtual TextureType GetType() const { return OBJECTID_TEX; }
virtual float GetFloatValue(const HitPoint &hitPoint) const;
virtual luxrays::Spectrum GetSpectrumValue(const HitPoint &hitPoint) const;
// The following methods don't make very much sense in this case. I have no
// information about the color.
virtual float Y() const { return 1.f; }
virtual float Filter() const { return 1.f; }

virtual luxrays::Properties ToProperties(const ImageMapCache &imgMapCache, const bool useRealFileName) const;
};

//------------------------------------------------------------------------------
// ObjectIDColor texture
//------------------------------------------------------------------------------

class ObjectIDColorTexture : public Texture {
public:
ObjectIDColorTexture() { }
virtual ~ObjectIDColorTexture() { }

virtual TextureType GetType() const { return OBJECTID_COLOR_TEX; }
virtual float GetFloatValue(const HitPoint &hitPoint) const;
virtual luxrays::Spectrum GetSpectrumValue(const HitPoint &hitPoint) const;
// The following methods don't make very much sense in this case. I have no
// information about the color.
virtual float Y() const { return 1.f; }
virtual float Filter() const { return 1.f; }

virtual luxrays::Properties ToProperties(const ImageMapCache &imgMapCache, const bool useRealFileName) const;
};

//------------------------------------------------------------------------------
// ObjectIDNormalized texture
//------------------------------------------------------------------------------

class ObjectIDNormalizedTexture : public Texture {
public:
ObjectIDNormalizedTexture() { }
virtual ~ObjectIDNormalizedTexture() { }

virtual TextureType GetType() const { return OBJECTID_NORMALIZED_TEX; }
virtual float GetFloatValue(const HitPoint &hitPoint) const;
virtual luxrays::Spectrum GetSpectrumValue(const HitPoint &hitPoint) const;
// The following methods don't make very much sense in this case. I have no
// information about the color.
virtual float Y() const { return 1.f; }
virtual float Filter() const { return 1.f; }

virtual luxrays::Properties ToProperties(const ImageMapCache &imgMapCache, const bool useRealFileName) const;
};

}

#endif /* _SLG_OBJECT_ID_H */
5 changes: 3 additions & 2 deletions include/slg/textures/texture.h
Expand Up @@ -55,12 +55,13 @@ typedef enum {
CONST_FLOAT, CONST_FLOAT3, IMAGEMAP, SCALE_TEX, FRESNEL_APPROX_N, CONST_FLOAT, CONST_FLOAT3, IMAGEMAP, SCALE_TEX, FRESNEL_APPROX_N,
FRESNEL_APPROX_K, MIX_TEX, ADD_TEX, SUBTRACT_TEX, HITPOINTCOLOR, HITPOINTALPHA, FRESNEL_APPROX_K, MIX_TEX, ADD_TEX, SUBTRACT_TEX, HITPOINTCOLOR, HITPOINTALPHA,
HITPOINTGREY, NORMALMAP_TEX, BLACKBODY_TEX, IRREGULARDATA_TEX, DENSITYGRID_TEX, HITPOINTGREY, NORMALMAP_TEX, BLACKBODY_TEX, IRREGULARDATA_TEX, DENSITYGRID_TEX,
ABS_TEX, CLAMP_TEX, BILERP_TEX, COLORDEPTH_TEX, HSV_TEX, DIVIDE_TEX, REMAP_TEX, // 23 textures ABS_TEX, CLAMP_TEX, BILERP_TEX, COLORDEPTH_TEX, HSV_TEX, DIVIDE_TEX, REMAP_TEX,
OBJECTID_TEX, OBJECTID_COLOR_TEX, OBJECTID_NORMALIZED_TEX, // 26 textures
// Procedural textures // Procedural textures
BLENDER_BLEND, BLENDER_CLOUDS, BLENDER_DISTORTED_NOISE, BLENDER_MAGIC, BLENDER_MARBLE, BLENDER_BLEND, BLENDER_CLOUDS, BLENDER_DISTORTED_NOISE, BLENDER_MAGIC, BLENDER_MARBLE,
BLENDER_MUSGRAVE, BLENDER_NOISE, BLENDER_STUCCI, BLENDER_WOOD, BLENDER_VORONOI, BLENDER_MUSGRAVE, BLENDER_NOISE, BLENDER_STUCCI, BLENDER_WOOD, BLENDER_VORONOI,
CHECKERBOARD2D, CHECKERBOARD3D, CLOUD_TEX, FBM_TEX, CHECKERBOARD2D, CHECKERBOARD3D, CLOUD_TEX, FBM_TEX,
MARBLE, DOTS, BRICK, WINDY, WRINKLED, UV_TEX, BAND_TEX, //41 textures MARBLE, DOTS, BRICK, WINDY, WRINKLED, UV_TEX, BAND_TEX, // 41 textures
// Fresnel textures // Fresnel textures
FRESNELCOLOR_TEX, FRESNELCONST_TEX FRESNELCOLOR_TEX, FRESNELCONST_TEX
} TextureType; } TextureType;
Expand Down
1 change: 1 addition & 0 deletions src/slg/CMakeLists.txt
Expand Up @@ -426,6 +426,7 @@ set(SLG_CORE_SRCS
${LuxRays_SOURCE_DIR}/src/slg/textures/marble.cpp ${LuxRays_SOURCE_DIR}/src/slg/textures/marble.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/mixtex.cpp ${LuxRays_SOURCE_DIR}/src/slg/textures/mixtex.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/normalmap.cpp ${LuxRays_SOURCE_DIR}/src/slg/textures/normalmap.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/object_id.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/remap.cpp ${LuxRays_SOURCE_DIR}/src/slg/textures/remap.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/scale.cpp ${LuxRays_SOURCE_DIR}/src/slg/textures/scale.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/subtract.cpp ${LuxRays_SOURCE_DIR}/src/slg/textures/subtract.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/slg/bsdf/bsdf.cpp
Expand Up @@ -34,6 +34,7 @@ void BSDF::Init(const bool fixedFromLight, const Scene &scene, const Ray &ray,


// Get the scene object // Get the scene object
sceneObject = scene.objDefs.GetSceneObject(rayHit.meshIndex); sceneObject = scene.objDefs.GetSceneObject(rayHit.meshIndex);
hitPoint.objectID = sceneObject->GetID();


// Get the triangle // Get the triangle
mesh = sceneObject->GetExtMesh(); mesh = sceneObject->GetExtMesh();
Expand Down Expand Up @@ -110,6 +111,8 @@ void BSDF::Init(const bool fixedFromLight, const Scene &scene, const luxrays::Ra
triangleLightSource = NULL; triangleLightSource = NULL;


hitPoint.uv = UV(0.f, 0.f); hitPoint.uv = UV(0.f, 0.f);

hitPoint.objectID = 0;


// Build the local reference system // Build the local reference system
frame.SetFromZ(hitPoint.shadeN); frame.SetFromZ(hitPoint.shadeN);
Expand Down
1 change: 1 addition & 0 deletions src/slg/lights/trianglelight.cpp
Expand Up @@ -95,6 +95,7 @@ Spectrum TriangleLight::Emit(const Scene &scene,
// Use relevant volume? // Use relevant volume?
hitPoint.interiorVolume = NULL; hitPoint.interiorVolume = NULL;
hitPoint.exteriorVolume = NULL; hitPoint.exteriorVolume = NULL;
hitPoint.objectID = 0xffffffffu; // TODO get correct objectID
hitPoint.uv = mesh->InterpolateTriUV(triangleIndex, b1, b2); hitPoint.uv = mesh->InterpolateTriUV(triangleIndex, b1, b2);
mesh->GetDifferentials(Transform::TRANS_IDENTITY, triangleIndex, hitPoint.shadeN, mesh->GetDifferentials(Transform::TRANS_IDENTITY, triangleIndex, hitPoint.shadeN,
&hitPoint.dpdu, &hitPoint.dpdv, &hitPoint.dpdu, &hitPoint.dpdv,
Expand Down
2 changes: 1 addition & 1 deletion src/slg/scene/parseobjects.cpp
Expand Up @@ -51,7 +51,7 @@ void Scene::ParseObjects(const Properties &props) {
} }
} }


// In order to have harlequin colors with MATERIAL_ID output // In order to have harlequin colors with OBJECT_ID output
const u_int objID = ((u_int)(RadicalInverse(objDefs.GetSize() + 1, 2) * 255.f + .5f)) | const u_int objID = ((u_int)(RadicalInverse(objDefs.GetSize() + 1, 2) * 255.f + .5f)) |
(((u_int)(RadicalInverse(objDefs.GetSize() + 1, 3) * 255.f + .5f)) << 8) | (((u_int)(RadicalInverse(objDefs.GetSize() + 1, 3) * 255.f + .5f)) << 8) |
(((u_int)(RadicalInverse(objDefs.GetSize() + 1, 5) * 255.f + .5f)) << 16); (((u_int)(RadicalInverse(objDefs.GetSize() + 1, 5) * 255.f + .5f)) << 16);
Expand Down
7 changes: 7 additions & 0 deletions src/slg/scene/parsetextures.cpp
Expand Up @@ -61,6 +61,7 @@
#include "slg/textures/marble.h" #include "slg/textures/marble.h"
#include "slg/textures/mix.h" #include "slg/textures/mix.h"
#include "slg/textures/normalmap.h" #include "slg/textures/normalmap.h"
#include "slg/textures/object_id.h"
#include "slg/textures/remap.h" #include "slg/textures/remap.h"
#include "slg/textures/scale.h" #include "slg/textures/scale.h"
#include "slg/textures/subtract.h" #include "slg/textures/subtract.h"
Expand Down Expand Up @@ -508,6 +509,12 @@ Texture *Scene::CreateTexture(const string &texName, const Properties &props) {
const Texture *targetMin = GetTexture(props.Get(Property(propName + ".targetmin")(0.f))); const Texture *targetMin = GetTexture(props.Get(Property(propName + ".targetmin")(0.f)));
const Texture *targetMax = GetTexture(props.Get(Property(propName + ".targetmax")(1.f))); const Texture *targetMax = GetTexture(props.Get(Property(propName + ".targetmax")(1.f)));
tex = new RemapTexture(value, sourceMin, sourceMax, targetMin, targetMax); tex = new RemapTexture(value, sourceMin, sourceMax, targetMin, targetMax);
} else if (texType == "objectid") {
tex = new ObjectIDTexture();
} else if (texType == "objectidcolor") {
tex = new ObjectIDColorTexture();
} else if (texType == "objectidnormalized") {
tex = new ObjectIDNormalizedTexture();
} else } else
throw runtime_error("Unknown texture type: " + texType); throw runtime_error("Unknown texture type: " + texType);


Expand Down
89 changes: 89 additions & 0 deletions src/slg/textures/object_id.cpp
@@ -0,0 +1,89 @@
/***************************************************************************
* Copyright 1998-2018 by authors (see AUTHORS.txt) *
* *
* This file is part of LuxCoreRender. *
* *
* 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. *
***************************************************************************/

#include "slg/textures/object_id.h"

using namespace std;
using namespace luxrays;
using namespace slg;

//------------------------------------------------------------------------------
// ObjectID texture
//------------------------------------------------------------------------------

float ObjectIDTexture::GetFloatValue(const HitPoint &hitPoint) const {
return static_cast<float>(hitPoint.objectID);
}

Spectrum ObjectIDTexture::GetSpectrumValue(const HitPoint &hitPoint) const {
return Spectrum(hitPoint.objectID);
}

Properties ObjectIDTexture::ToProperties(const ImageMapCache &imgMapCache, const bool useRealFileName) const {
Properties props;

const string name = GetName();
props.Set(Property("scene.textures." + name + ".type")("objectid"));

return props;
}

//------------------------------------------------------------------------------
// ObjectIDColor texture
//------------------------------------------------------------------------------

float ObjectIDColorTexture::GetFloatValue(const HitPoint &hitPoint) const {
return GetSpectrumValue(hitPoint).Y();
}

Spectrum ObjectIDColorTexture::GetSpectrumValue(const HitPoint &hitPoint) const {
const u_int objID = hitPoint.objectID;
return Spectrum((objID & 0x0000ffu) * ( 1.f / 255.f),
((objID & 0x00ff00u) >> 8) * ( 1.f / 255.f),
((objID & 0xff0000u) >> 16) * ( 1.f / 255.f));
}

Properties ObjectIDColorTexture::ToProperties(const ImageMapCache &imgMapCache, const bool useRealFileName) const {
Properties props;

const string name = GetName();
props.Set(Property("scene.textures." + name + ".type")("objectidcolor"));

return props;
}

//------------------------------------------------------------------------------
// ObjectIDNormalized texture
//------------------------------------------------------------------------------

float ObjectIDNormalizedTexture::GetFloatValue(const HitPoint &hitPoint) const {
return static_cast<float>(hitPoint.objectID) * (1.f / 0xffffffu);
}

Spectrum ObjectIDNormalizedTexture::GetSpectrumValue(const HitPoint &hitPoint) const {
return Spectrum(GetFloatValue(hitPoint));
}

Properties ObjectIDNormalizedTexture::ToProperties(const ImageMapCache &imgMapCache, const bool useRealFileName) const {
Properties props;

const string name = GetName();
props.Set(Property("scene.textures." + name + ".type")("objectidnormalized"));

return props;
}
3 changes: 2 additions & 1 deletion src/slg/volumes/clear.cpp
Expand Up @@ -58,7 +58,8 @@ float ClearVolume::Scatter(const Ray &ray, const float u,
0.f, // It doesn't matter here 0.f, // It doesn't matter here
Transform(), Transform(),
this, this, // It doesn't matter here this, this, // It doesn't matter here
true, true // It doesn't matter here true, true, // It doesn't matter here
0
}; };


const float distance = ray.maxt - ray.mint; const float distance = ray.maxt - ray.mint;
Expand Down
3 changes: 2 additions & 1 deletion src/slg/volumes/heterogenous.cpp
Expand Up @@ -79,7 +79,8 @@ float HeterogeneousVolume::Scatter(const Ray &ray, const float u,
0.f, // It doesn't matter here 0.f, // It doesn't matter here
Transform(), Transform(),
this, this, // It doesn't matter here this, this, // It doesn't matter here
true, true // It doesn't matter here true, true, // It doesn't matter here
0
}; };


for (u_int s = 0; s < steps; ++s) { for (u_int s = 0; s < steps; ++s) {
Expand Down
3 changes: 2 additions & 1 deletion src/slg/volumes/homogenous.cpp
Expand Up @@ -114,7 +114,8 @@ float HomogeneousVolume::Scatter(const Ray &ray, const float u,
0.f, // It doesn't matter here 0.f, // It doesn't matter here
Transform(), Transform(),
this, this, // It doesn't matter here this, this, // It doesn't matter here
true, true // It doesn't matter here true, true, // It doesn't matter here
0
}; };


const Spectrum sigmaA = SigmaA(hitPoint); const Spectrum sigmaA = SigmaA(hitPoint);
Expand Down

0 comments on commit fa1b6c2

Please sign in to comment.