Created
February 7, 2019 12:06
-
-
Save zpelgrims/f68b54c5db037506d39979f44d6e6823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ai.h> | |
#include <string> | |
#include <cstring> | |
AI_SHADER_NODE_EXPORT_METHODS(directionalOcclusionMethods); | |
struct ShaderData { | |
AtSampler* sampler; | |
AtString trace_set; | |
}; | |
enum DustParams { | |
p_axis, | |
p_radius, | |
p_spread, | |
p_traceSet, | |
p_samples | |
}; | |
node_parameters { | |
AiParameterVec("axis", 0.0, 1.0, 0.0); | |
AiParameterFlt("radius", 20.0); | |
AiParameterFlt("spread", 1.0); | |
AiParameterStr("traceSet", ""); | |
AiParameterInt("samples", 4); | |
} | |
node_initialize { | |
ShaderData* data = new ShaderData; | |
AiNodeSetLocalData(node, data); | |
data->sampler = NULL; | |
} | |
node_update { | |
ShaderData *data = (ShaderData*)AiNodeGetLocalData(node); | |
data->sampler = AiSampler(1, AiNodeGetInt(node, "samples"), 2); | |
data->trace_set = AiNodeGetStr(node, "traceset"); | |
} | |
node_finish { | |
if (AiNodeGetLocalData(node)){ | |
ShaderData* data = (ShaderData*)AiNodeGetLocalData(node); | |
AiSamplerDestroy(data->sampler); | |
AiNodeSetLocalData(node, NULL); | |
delete data; | |
} | |
} | |
shader_evaluate { | |
ShaderData* data = (ShaderData*)AiNodeGetLocalData(node); | |
const float radius = AiShaderEvalParamFlt(p_radius); | |
const float spread = AiShaderEvalParamFlt(p_spread); | |
const AtVector axis = AiShaderEvalParamVec(p_axis); | |
AtRGB result = AI_RGB_BLACK; | |
if (data->trace_set.length()) | |
{ | |
AiShaderGlobalsSetTraceSet(sg, data->trace_set, true); | |
} | |
sg->out.RGB() = (AI_RGB_WHITE - AiOcclusion(axis, axis, sg, 0.0, radius, spread, 0.0, data->sampler, NULL)); | |
AiShaderGlobalsUnsetTraceSet(sg); | |
} | |
node_loader { | |
if (i > 0){return false;} | |
node->methods = directionalOcclusionMethods; | |
node->output_type = AI_TYPE_RGB; | |
node->name = "directionalOcclusion"; | |
node->node_type = AI_NODE_SHADER; | |
strcpy(node->version, AI_VERSION); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment