text: #include <string>
  namespace slg { namespace ocl {
  std::string KernelSource_materialdefs_funcs_archglass = 
  "#line 2 \"materialdefs_funcs_archglass.cl\"\n"
  "\n"
  "/***************************************************************************\n"
  " * Copyright 1998-2018 by authors (see AUTHORS.txt)                        *\n"
  " *                                                                         *\n"
  " *   This file is part of LuxCoreRender.                                   *\n"
  " *                                                                         *\n"
  " * Licensed under the Apache License, Version 2.0 (the \"License\");         *\n"
  " * you may not use this file except in compliance with the License.        *\n"
  " * You may obtain a copy of the License at                                 *\n"
  " *                                                                         *\n"
  " *     http://www.apache.org/licenses/LICENSE-2.0                          *\n"
  " *                                                                         *\n"
  " * Unless required by applicable law or agreed to in writing, software     *\n"
  " * distributed under the License is distributed on an \"AS IS\" BASIS,       *\n"
  " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*\n"
  " * See the License for the specific language governing permissions and     *\n"
  " * limitations under the License.                                          *\n"
  " ***************************************************************************/\n"
  "\n"
  "#if defined(PARAM_HAS_VOLUMES)\n"
  "OPENCL_FORCE_INLINE float ExtractExteriorIors(__global HitPoint *hitPoint, const uint exteriorIorTexIndex\n"
  "		TEXTURES_PARAM_DECL) {\n"
  "	uint extIndex = NULL_INDEX;\n"
  "	if (exteriorIorTexIndex != NULL_INDEX)\n"
  "		extIndex = exteriorIorTexIndex;\n"
  "	else {\n"
  "		const uint hitPointExteriorIorTexIndex = hitPoint->exteriorIorTexIndex;\n"
  "		if (hitPointExteriorIorTexIndex != NULL_INDEX)\n"
  "			extIndex = hitPointExteriorIorTexIndex;\n"
  "	}\n"
  "	return (extIndex == NULL_INDEX) ? 1.f : Texture_GetFloatValue(extIndex, hitPoint\n"
  "			TEXTURES_PARAM);\n"
  "}\n"
  "\n"
  "OPENCL_FORCE_INLINE float ExtractInteriorIors(__global HitPoint *hitPoint, const uint interiorIorTexIndex\n"
  "		TEXTURES_PARAM_DECL) {\n"
  "	uint intIndex = NULL_INDEX;\n"
  "	if (interiorIorTexIndex != NULL_INDEX)\n"
  "		intIndex = interiorIorTexIndex;\n"
  "	else {\n"
  "		const uint hitPointInteriorIorTexIndex = hitPoint->interiorIorTexIndex;\n"
  "		if (hitPointInteriorIorTexIndex != NULL_INDEX)\n"
  "			intIndex = hitPointInteriorIorTexIndex;\n"
  "	}\n"
  "	return (intIndex == NULL_INDEX) ? 1.f : Texture_GetFloatValue(intIndex, hitPoint\n"
  "			TEXTURES_PARAM);\n"
  "}\n"
  "#endif\n"
  "\n"
  "//------------------------------------------------------------------------------\n"
  "// ArchGlass material\n"
  "//------------------------------------------------------------------------------\n"
  "\n"
  "#if defined (PARAM_ENABLE_MAT_ARCHGLASS)\n"
  "\n"
  "OPENCL_FORCE_INLINE BSDFEvent ArchGlassMaterial_GetEventTypes() {\n"
  "	return SPECULAR | REFLECT | TRANSMIT;\n"
  "}\n"
  "\n"
  "OPENCL_FORCE_INLINE bool ArchGlassMaterial_IsDelta() {\n"
  "	return true;\n"
  "}\n"
  "\n"
  "OPENCL_FORCE_NOT_INLINE float3 ArchGlassMaterial_EvalSpecularReflection(__global HitPoint *hitPoint,\n"
  "		const float3 localFixedDir, const float3 kr,\n"
  "		const float nc, const float nt,\n"
  "		float3 *localSampledDir) {\n"
  "	if (Spectrum_IsBlack(kr))\n"
  "		return BLACK;\n"
  "\n"
  "	const float costheta = CosTheta(localFixedDir);\n"
  "	if (costheta <= 0.f)\n"
  "		return BLACK;\n"
  "\n"
  "	*localSampledDir = (float3)(-localFixedDir.x, -localFixedDir.y, localFixedDir.z);\n"
  "\n"
  "	const float ntc = nt / nc;\n"
  "	return kr * FresnelCauchy_Evaluate(ntc, costheta);\n"
  "}\n"
  "\n"
  "OPENCL_FORCE_NOT_INLINE float3 ArchGlassMaterial_EvalSpecularTransmission(__global HitPoint *hitPoint,\n"
  "		const float3 localFixedDir, const float3 kt,\n"
  "		const float nc, const float nt, float3 *localSampledDir) {\n"
  "	if (Spectrum_IsBlack(kt))\n"
  "		return BLACK;\n"
  "\n"
  "	// Note: there can not be total internal reflection for \n"
  "	\n"
  "	*localSampledDir = -localFixedDir;\n"
  "\n"
  "	const float ntc = nt / nc;\n"
  "	const float costheta = CosTheta(localFixedDir);\n"
  "	const bool entering = (costheta > 0.f);\n"
  "	float ce;\n"
  "//	if (!hitPoint.fromLight) {\n"
  "		if (entering)\n"
  "			ce = 0.f;\n"
  "		else\n"
  "			ce = FresnelCauchy_Evaluate(ntc, -costheta);\n"
  "//	} else {\n"
  "//		if (entering)\n"
  "//			ce = FresnelTexture::CauchyEvaluate(ntc, costheta);\n"
  "//		else\n"
  "//			ce = 0.f;\n"
  "//	}\n"
  "	const float factor = 1.f - ce;\n"
  "	const float result = (1.f + factor * factor) * ce;\n"
  "\n"
  "	return (1.f - result) * kt;\n"
  "}\n"
  "\n"
  "#if defined(PARAM_HAS_PASSTHROUGH)\n"
  "OPENCL_FORCE_NOT_INLINE float3 ArchGlassMaterial_GetPassThroughTransparency(__global const Material *material,\n"
  "		__global HitPoint *hitPoint, const float3 localFixedDir, const float passThroughEvent\n"
  "		TEXTURES_PARAM_DECL) {\n"
  "	const float3 kt = Spectrum_Clamp(Texture_GetSpectrumValue(material->archglass.ktTexIndex, hitPoint\n"
  "		TEXTURES_PARAM));\n"
  "	const float3 kr = Spectrum_Clamp(Texture_GetSpectrumValue(material->archglass.krTexIndex, hitPoint\n"
  "		TEXTURES_PARAM));\n"
  "\n"
  "	const float nc = Spectrum_Filter(ExtractExteriorIors(hitPoint,\n"
  "			material->archglass.exteriorIorTexIndex\n"
  "			TEXTURES_PARAM));\n"
  "	const float nt = Spectrum_Filter(ExtractInteriorIors(hitPoint,\n"
  "			material->archglass.interiorIorTexIndex\n"
  "			TEXTURES_PARAM));\n"
  "\n"
  "	float3 transLocalSampledDir; \n"
  "	const float3 trans = ArchGlassMaterial_EvalSpecularTransmission(hitPoint, localFixedDir,\n"
  "			kt, nc, nt, &transLocalSampledDir);\n"
  "	\n"
  "	float3 reflLocalSampledDir;\n"
  "	const float3 refl = ArchGlassMaterial_EvalSpecularReflection(hitPoint, localFixedDir,\n"
  "			kr, nc, nt, &reflLocalSampledDir);\n"
  "\n"
  "	// Decide to transmit or reflect\n"
  "	float threshold;\n"
  "	if (!Spectrum_IsBlack(refl)) {\n"
  "		if (!Spectrum_IsBlack(trans)) {\n"
  "			// Importance sampling\n"
  "			const float reflFilter = Spectrum_Filter(refl);\n"
  "			const float transFilter = Spectrum_Filter(trans);\n"
  "			threshold = transFilter / (reflFilter + transFilter);\n"
  "			\n"
  "			if (passThroughEvent < threshold) {\n"
  "				// Transmit\n"
  "				return trans / threshold;\n"
  "			} else {\n"
  "				// Reflect\n"
  "				return BLACK;\n"
  "			}\n"
  "		} else\n"
  "			return BLACK;\n"
  "	} else {\n"
  "		if (!Spectrum_IsBlack(trans)) {\n"
  "			// Transmit\n"
  "\n"
  "			// threshold = 1 so I avoid the / threshold\n"
  "			return trans;\n"
  "		} else\n"
  "			return BLACK;\n"
  "	}\n"
  "}\n"
  "#endif\n"
  "\n"
  "OPENCL_FORCE_INLINE float3 ArchGlassMaterial_Evaluate(\n"
  "		__global HitPoint *hitPoint, const float3 lightDir, const float3 eyeDir,\n"
  "		BSDFEvent *event, float *directPdfW,\n"
  "		const float3 ktTexVal, const float3 krTexVal,\n"
  "		const float nc, const float nt) {\n"
  "	return BLACK;\n"
  "}\n"
  "\n"
  "OPENCL_FORCE_NOT_INLINE float3 ArchGlassMaterial_Sample(\n"
  "		__global HitPoint *hitPoint, const float3 localFixedDir, float3 *localSampledDir,\n"
  "		const float u0, const float u1,\n"
  "#if defined(PARAM_HAS_PASSTHROUGH)\n"
  "		const float passThroughEvent,\n"
  "#endif\n"
  "		float *pdfW, float *absCosSampledDir, BSDFEvent *event,\n"
  "		const float3 ktTexVal, const float3 krTexVal,\n"
  "		const float nc, const float nt) {\n"
  "	const float3 kt = Spectrum_Clamp(ktTexVal);\n"
  "	const float3 kr = Spectrum_Clamp(krTexVal);\n"
  "\n"
  "	float3 transLocalSampledDir; \n"
  "	const float3 trans = ArchGlassMaterial_EvalSpecularTransmission(hitPoint, localFixedDir,\n"
  "			kt, nc, nt, &transLocalSampledDir);\n"
  "	\n"
  "	float3 reflLocalSampledDir;\n"
  "	const float3 refl = ArchGlassMaterial_EvalSpecularReflection(hitPoint, localFixedDir,\n"
  "			kr, nc, nt, &reflLocalSampledDir);\n"
  "\n"
  "	// Decide to transmit or reflect\n"
  "	float threshold;\n"
  "	if (!Spectrum_IsBlack(refl)) {\n"
  "		if (!Spectrum_IsBlack(trans)) {\n"
  "			// Importance sampling\n"
  "			const float reflFilter = Spectrum_Filter(refl);\n"
  "			const float transFilter = Spectrum_Filter(trans);\n"
  "			threshold = transFilter / (reflFilter + transFilter);\n"
  "		} else\n"
  "			threshold = 0.f;\n"
  "	} else {\n"
  "		// ArchGlassMaterial::Sample() can be called only if ArchGlassMaterial::GetPassThroughTransparency()\n"
  "		// has detected a reflection or a mixed reflection/transmission.\n"
  "		// Here, there was no reflection at all so I return black.\n"
  "		return BLACK;\n"
  "	}\n"
  "\n"
  "	float3 result;\n"
  "	if (passThroughEvent < threshold) {\n"
  "		// Transmit\n"
  "\n"
  "		*localSampledDir = transLocalSampledDir;\n"
  "\n"
  "		*event = SPECULAR | TRANSMIT;\n"
  "		*pdfW = threshold;\n"
  "		\n"
  "		result = trans;\n"
  "	} else {\n"
  "		// Reflect\n"
  "		*localSampledDir = reflLocalSampledDir;\n"
  "\n"
  "		*event = SPECULAR | REFLECT;\n"
  "		*pdfW = 1.f - threshold;\n"
  "\n"
  "		result = refl;\n"
  "	}\n"
  "\n"
  "	*absCosSampledDir = fabs(CosTheta(*localSampledDir));\n"
  "\n"
  "	return result / *pdfW;\n"
  "}\n"
  "\n"
  "#endif\n"
  ; } }
  