Skip to content
Permalink
Browse files

add C++ code for divide texture (issue #118)

  • Loading branch information...
Theverat committed Jun 18, 2018
1 parent 4d7bcd7 commit ce6e23c244b1bb426c1dcd13099a41982e565b88
@@ -0,0 +1,71 @@
/***************************************************************************
* 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_DIVIDETEX_H
#define _SLG_DIVIDETEX_H

#include "slg/textures/texture.h"

namespace slg {

//------------------------------------------------------------------------------
// Divide texture
//------------------------------------------------------------------------------

class DivideTexture : public Texture {
public:
DivideTexture(const Texture *t1, const Texture *t2) : tex1(t1), tex2(t2) { }
virtual ~DivideTexture() { }

virtual TextureType GetType() const { return DIVIDE_TEX; }
virtual float GetFloatValue(const HitPoint &hitPoint) const;
virtual luxrays::Spectrum GetSpectrumValue(const HitPoint &hitPoint) const;
virtual float Y() const;
virtual float Filter() const;

virtual void AddReferencedTextures(boost::unordered_set<const Texture *> &referencedTexs) const {
Texture::AddReferencedTextures(referencedTexs);

tex1->AddReferencedTextures(referencedTexs);
tex2->AddReferencedTextures(referencedTexs);
}
virtual void AddReferencedImageMaps(boost::unordered_set<const ImageMap *> &referencedImgMaps) const {
tex1->AddReferencedImageMaps(referencedImgMaps);
tex2->AddReferencedImageMaps(referencedImgMaps);
}

virtual void UpdateTextureReferences(const Texture *oldTex, const Texture *newTex) {
if (tex1 == oldTex)
tex1 = newTex;
if (tex2 == oldTex)
tex2 = newTex;
}

const Texture *GetTexture1() const { return tex1; }
const Texture *GetTexture2() const { return tex2; }

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

private:
const Texture *tex1;
const Texture *tex2;
};

}

#endif /* _SLG_DIVIDETEX_H */
@@ -55,7 +55,7 @@ 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, // 20 textures
ABS_TEX, CLAMP_TEX, BILERP_TEX, COLORDEPTH_TEX, HSV_TEX, DIVIDE_TEX, // 22 textures
// Procedural textures
BLENDER_BLEND, BLENDER_CLOUDS, BLENDER_DISTORTED_NOISE, BLENDER_MAGIC, BLENDER_MARBLE,
BLENDER_MUSGRAVE, BLENDER_NOISE, BLENDER_STUCCI, BLENDER_WOOD, BLENDER_VORONOI,
@@ -95,7 +95,7 @@ set(BCD_SRCS
${LuxRays_SOURCE_DIR}/deps/bcd-1.1/src/core/Utils.cpp
)

SOURCE_GROUP("Source Files\\BCD Library" FILES ${BCD_SRCS})
SOURCE_GROUP("Source Files\\BCD Library" FILES ${BCD_SRCS})

include_directories(${LuxRays_SOURCE_DIR}/deps/eigen-3.3.4)
include_directories(${LuxRays_SOURCE_DIR}/deps/bcd-1.1/include)
@@ -133,7 +133,7 @@ set(OPENVDB_SRCS
${LuxRays_SOURCE_DIR}/deps/openvdb-3.1.0/openvdb/util/Util.cc
)

SOURCE_GROUP("Source Files\\OpenVDB Library" FILES ${OPENVDB_SRCS})
SOURCE_GROUP("Source Files\\OpenVDB Library" FILES ${OPENVDB_SRCS})

include_directories(${LuxRays_SOURCE_DIR}/deps/openvdb-3.1.0)

@@ -401,6 +401,7 @@ set(SLG_CORE_SRCS
${LuxRays_SOURCE_DIR}/src/slg/textures/constfloat.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/constfloat3.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/cloud.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/divide.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/dots.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/densitygrid.cpp
${LuxRays_SOURCE_DIR}/src/slg/textures/fbm.cpp
@@ -437,7 +438,7 @@ set(SLG_CORE_SRCS
${LuxRays_SOURCE_DIR}/src/slg/rendersession.cpp
${LuxRays_SOURCE_DIR}/src/slg/renderstate.cpp
)
SOURCE_GROUP("Source Files\\SLG Core Library" FILES ${SLG_CORE_SRCS})
SOURCE_GROUP("Source Files\\SLG Core Library" FILES ${SLG_CORE_SRCS})

add_library(slg-core STATIC ${SLG_CORE_SRCS})

@@ -600,7 +601,7 @@ set(SLG_FILM_SRCS
${LuxRays_SOURCE_DIR}/src/slg/film/imagepipeline/plugins/tonemaps/reinhard02.cpp
${LuxRays_SOURCE_DIR}/src/slg/film/imagepipeline/plugins/tonemaps/tonemap.cpp
)
SOURCE_GROUP("Source Files\\SLG Film Library" FILES ${SLG_FILM_SRCS})
SOURCE_GROUP("Source Files\\SLG Film Library" FILES ${SLG_FILM_SRCS})

add_library(slg-film STATIC ${SLG_FILM_SRCS})

@@ -41,6 +41,7 @@
#include "slg/textures/constfloat.h"
#include "slg/textures/constfloat3.h"
#include "slg/textures/cloud.h"
#include "slg/textures/divide.h"
#include "slg/textures/dots.h"
#include "slg/textures/densitygrid.h"
#include "slg/textures/fbm.h"
@@ -491,6 +492,10 @@ Texture *Scene::CreateTexture(const string &texName, const Properties &props) {
const Texture *v = GetTexture(props.Get(Property(propName + ".value")(1.f)));

tex = new HsvTexture(t, h, s, v);
} else if (texType == "divide") {
const Texture *tex1 = GetTexture(props.Get(Property(propName + ".texture1")(1.f)));
const Texture *tex2 = GetTexture(props.Get(Property(propName + ".texture2")(1.f)));
tex = new DivideTexture(tex1, tex2);
} else
throw runtime_error("Unknown texture type: " + texType);

@@ -0,0 +1,74 @@
/***************************************************************************
* 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/divide.h"

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

//------------------------------------------------------------------------------
// Divide texture
//------------------------------------------------------------------------------

float DivideTexture::GetFloatValue(const HitPoint &hitPoint) const {
const float value2 = tex2->GetFloatValue(hitPoint);
if (value2 == 0.f)
return 0.f;

const float value1 = tex1->GetFloatValue(hitPoint);
return value1 / value2;
}

Spectrum DivideTexture::GetSpectrumValue(const HitPoint &hitPoint) const {
const Spectrum value2 = tex2->GetSpectrumValue(hitPoint);
if (value2.Black())
return Spectrum(0.f);

const Spectrum value1 = tex1->GetSpectrumValue(hitPoint);
return value1 / value2;
}

float DivideTexture::Y() const {
const float Y2 = tex2->Y();
if (Y2 == 0.f)
return 0.f;

const float Y1 = tex1->Y();
return Y1 / Y2;
}

float DivideTexture::Filter() const {
const float filter2 = tex2->Filter();
if (filter2 == 0.f)
return 0.f;

const float filter1 = tex1->Filter();
return filter1 / filter2;
}

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

const string name = GetName();
props.Set(Property("scene.textures." + name + ".type")("divide"));
props.Set(Property("scene.textures." + name + ".texture1")(tex1->GetName()));
props.Set(Property("scene.textures." + name + ".texture2")(tex2->GetName()));

return props;
}

0 comments on commit ce6e23c

Please sign in to comment.
You can’t perform that action at this time.