Permalink
Browse files

add objectID to hitpoint struct, add objectID textures

  • Loading branch information...
Theverat committed Oct 1, 2018
1 parent b52b148 commit fa1b6c27b71f4f78849e44b6ef2d2700c8dff9ee
@@ -53,6 +53,7 @@ typedef struct {
// computation and scene default world volume)
const Volume *interiorVolume, *exteriorVolume;
bool fromLight, intoObject;
u_int objectID;
luxrays::Frame GetFrame() const { return luxrays::Frame(dpdu, dpdv, shadeN); }
} HitPoint;
@@ -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 */
@@ -55,12 +55,13 @@ typedef enum {
CONST_FLOAT, CONST_FLOAT3, IMAGEMAP, SCALE_TEX, FRESNEL_APPROX_N,
FRESNEL_APPROX_K, MIX_TEX, ADD_TEX, SUBTRACT_TEX, HITPOINTCOLOR, HITPOINTALPHA,
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
BLENDER_BLEND, BLENDER_CLOUDS, BLENDER_DISTORTED_NOISE, BLENDER_MAGIC, BLENDER_MARBLE,
BLENDER_MUSGRAVE, BLENDER_NOISE, BLENDER_STUCCI, BLENDER_WOOD, BLENDER_VORONOI,
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
FRESNELCOLOR_TEX, FRESNELCONST_TEX
} TextureType;
View
@@ -426,6 +426,7 @@ set(SLG_CORE_SRCS
${LuxRays_SOURCE_DIR}/src/slg/textures/marble.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/mixtex.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/scale.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/subtract.cpp
View
@@ -34,6 +34,7 @@ void BSDF::Init(const bool fixedFromLight, const Scene &scene, const Ray &ray,
// Get the scene object
sceneObject = scene.objDefs.GetSceneObject(rayHit.meshIndex);
hitPoint.objectID = sceneObject->GetID();
// Get the triangle
mesh = sceneObject->GetExtMesh();
@@ -110,6 +111,8 @@ void BSDF::Init(const bool fixedFromLight, const Scene &scene, const luxrays::Ra
triangleLightSource = NULL;
hitPoint.uv = UV(0.f, 0.f);
hitPoint.objectID = 0;
// Build the local reference system
frame.SetFromZ(hitPoint.shadeN);
@@ -95,6 +95,7 @@ Spectrum TriangleLight::Emit(const Scene &scene,
// Use relevant volume?
hitPoint.interiorVolume = NULL;
hitPoint.exteriorVolume = NULL;
hitPoint.objectID = 0xffffffffu; // TODO get correct objectID
hitPoint.uv = mesh->InterpolateTriUV(triangleIndex, b1, b2);
mesh->GetDifferentials(Transform::TRANS_IDENTITY, triangleIndex, hitPoint.shadeN,
&hitPoint.dpdu, &hitPoint.dpdv,
@@ -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)) |
(((u_int)(RadicalInverse(objDefs.GetSize() + 1, 3) * 255.f + .5f)) << 8) |
(((u_int)(RadicalInverse(objDefs.GetSize() + 1, 5) * 255.f + .5f)) << 16);
@@ -61,6 +61,7 @@
#include "slg/textures/marble.h"
#include "slg/textures/mix.h"
#include "slg/textures/normalmap.h"
#include "slg/textures/object_id.h"
#include "slg/textures/remap.h"
#include "slg/textures/scale.h"
#include "slg/textures/subtract.h"
@@ -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 *targetMax = GetTexture(props.Get(Property(propName + ".targetmax")(1.f)));
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
throw runtime_error("Unknown texture type: " + texType);
@@ -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;
}
@@ -58,7 +58,8 @@ float ClearVolume::Scatter(const Ray &ray, const float u,
0.f, // It doesn't matter here
Transform(),
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;
@@ -79,7 +79,8 @@ float HeterogeneousVolume::Scatter(const Ray &ray, const float u,
0.f, // It doesn't matter here
Transform(),
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) {
@@ -114,7 +114,8 @@ float HomogeneousVolume::Scatter(const Ray &ray, const float u,
0.f, // It doesn't matter here
Transform(),
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);

0 comments on commit fa1b6c2

Please sign in to comment.