forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightSamplerNodeGlsl.cpp
More file actions
57 lines (45 loc) · 1.85 KB
/
Copy pathLightSamplerNodeGlsl.cpp
File metadata and controls
57 lines (45 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//
#include <MaterialXGenGlsl/Nodes/LightSamplerNodeGlsl.h>
MATERIALX_NAMESPACE_BEGIN
namespace
{
const string SAMPLE_LIGHTS_FUNC_SIGNATURE = "void sampleLightSource(LightData light, vec3 position, out lightshader result)";
} // anonymous namespace
LightSamplerNodeGlsl::LightSamplerNodeGlsl()
{
_hash = std::hash<string>{}(SAMPLE_LIGHTS_FUNC_SIGNATURE);
}
ShaderNodeImplPtr LightSamplerNodeGlsl::create()
{
return std::make_shared<LightSamplerNodeGlsl>();
}
void LightSamplerNodeGlsl::emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
const ShaderGenerator& shadergen = context.getShaderGenerator();
// Emit light sampler function with all bound light types
shadergen.emitLine(SAMPLE_LIGHTS_FUNC_SIGNATURE, stage, false);
shadergen.emitFunctionBodyBegin(node, context, stage);
shadergen.emitLine("result.intensity = vec3(0.0)", stage);
shadergen.emitLine("result.direction = vec3(0.0)", stage);
HwLightShadersPtr lightShaders = context.getUserData<HwLightShaders>(HW::USER_DATA_LIGHT_SHADERS);
if (lightShaders)
{
string ifstatement = "if ";
for (const auto& it : lightShaders->get())
{
shadergen.emitLine(ifstatement + "(light." + shadergen.getLightDataTypevarString() + " == " + std::to_string(it.first) + ")", stage, false);
shadergen.emitScopeBegin(stage);
shadergen.emitFunctionCall(*it.second, context, stage);
shadergen.emitScopeEnd(stage);
ifstatement = "else if ";
}
}
shadergen.emitFunctionBodyEnd(node, context, stage);
}
}
MATERIALX_NAMESPACE_END