Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/constant_fold.cpp
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | bool ConstantFolder::try_bypass_or_make_constant(ShaderInput *input, float3 input_value, bool clamp) const | ||||
| else if(!clamp) { | else if(!clamp) { | ||||
| bypass(input->link); | bypass(input->link); | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Utility Functions for Constant Fold */ | |||||
| /* Code copied with very minimal edits from shaders/node_rgb_curves.osl */ | |||||
| float curves_ramp_lookup(const array<float3> &ramp, float at, int component) | |||||
| { | |||||
| int table_size = ramp.size(); | |||||
| if (at < 0.0f || at > 1.0f) { | |||||
| float t0, dy; | |||||
| if (at < 0.0f) { | |||||
| t0 = ramp[0][component]; | |||||
| dy = t0 - ramp[1][component]; | |||||
| at = -at; | |||||
| } | |||||
| else { | |||||
| t0 = ramp[table_size - 1][component]; | |||||
| dy = t0 - ramp[table_size - 2][component]; | |||||
| at = at - 1.0f; | |||||
| } | |||||
| return t0 + dy * at * (table_size - 1); | |||||
| } | |||||
| float f = clamp(at, 0.0f, 1.0f) * (table_size - 1); | |||||
| /* clamp int as well in case of NaN */ | |||||
| int i = (int)f; | |||||
| if (i < 0) i = 0; | |||||
| if (i >= table_size) i = table_size - 1; | |||||
| float t = f - (float)i; | |||||
| float result = ramp[i][component]; | |||||
| if (t > 0.0f) | |||||
| result = (1.0f - t) * result + t * ramp[i + 1][component]; | |||||
| return result; | |||||
| } | |||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||