本文整理汇总了C++中ShaderSource::add_const方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderSource::add_const方法的具体用法?C++ ShaderSource::add_const怎么用?C++ ShaderSource::add_const使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderSource
的用法示例。
在下文中一共展示了ShaderSource::add_const方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static void
create_blur_shaders(ShaderSource& vtx_source, ShaderSource& frg_source,
unsigned int radius, float sigma, BlurDirection direction)
{
vtx_source.append_file(GLMARK_DATA_PATH"/shaders/desktop.vert");
frg_source.append_file(GLMARK_DATA_PATH"/shaders/desktop-blur.frag");
/* Don't let the gaussian curve become too narrow */
if (sigma < 1.0)
sigma = 1.0;
unsigned int side = 2 * radius + 1;
for (unsigned int i = 0; i < radius + 1; i++) {
float s2 = 2.0 * sigma * sigma;
float k = 1.0 / std::sqrt(M_PI * s2) * std::exp( - (static_cast<float>(i) * i) / s2);
std::stringstream ss_tmp;
ss_tmp << "Kernel" << i;
frg_source.add_const(ss_tmp.str(), k);
}
std::stringstream ss;
ss << "result = " << std::endl;
if (direction == BlurDirectionHorizontal) {
for (unsigned int i = 0; i < side; i++) {
int offset = static_cast<int>(i - radius);
ss << "texture2D(Texture0, TextureCoord + vec2(" <<
offset << ".0 * TextureStepX, 0.0)) * Kernel" <<
std::abs(offset) << " +" << std::endl;
}
ss << "0.0 ;" << std::endl;
}
else if (direction == BlurDirectionVertical) {
for (unsigned int i = 0; i < side; i++) {
int offset = static_cast<int>(i - radius);
ss << "texture2D(Texture0, TextureCoord + vec2(0.0, " <<
offset << ".0 * TextureStepY)) * Kernel" <<
std::abs(offset) << " +" << std::endl;
}
ss << "0.0 ;" << std::endl;
}
else if (direction == BlurDirectionBoth) {
for (unsigned int i = 0; i < side; i++) {
int ioffset = static_cast<int>(i - radius);
for (unsigned int j = 0; j < side; j++) {
int joffset = static_cast<int>(j - radius);
ss << "texture2D(Texture0, TextureCoord + vec2(" <<
ioffset << ".0 * TextureStepX, " <<
joffset << ".0 * TextureStepY))" <<
" * Kernel" << std::abs(ioffset) <<
" * Kernel" << std::abs(joffset) << " +" << std::endl;
}
}
ss << " 0.0;" << std::endl;
}
frg_source.replace("$CONVOLUTION$", ss.str());
}
示例2: if
void
create_blur_shaders(ShaderSource& vtx_source, ShaderSource& frg_source,
unsigned int radius, float sigma, BlurRenderer::BlurDirection direction,
float tilt_shift)
{
vtx_source.append_file(GLMARK_DATA_PATH"/shaders/terrain-texture.vert");
frg_source.append_file(GLMARK_DATA_PATH"/shaders/terrain-blur.frag");
/* Don't let the gaussian curve become too narrow */
if (sigma < 1.0)
sigma = 1.0;
unsigned int side = 2 * radius + 1;
float values[radius];
float sum = 0.0;
for (unsigned int i = 0; i < radius + 1; i++) {
float s2 = 2.0 * sigma * sigma;
float k = 1.0 / std::sqrt(M_PI * s2) * std::exp( - (static_cast<float>(i) * i) / s2);
values[i] = k;
sum += k;
}
sum += sum - values[0];
for (unsigned int i = 0; i < radius + 1; i++) {
std::stringstream ss_tmp;
ss_tmp << "Kernel" << i;
frg_source.add_const(ss_tmp.str(), values[i] / sum);
}
frg_source.add_const("TiltShift", tilt_shift);
std::stringstream ss;
if (direction == BlurRenderer::BlurDirectionHorizontal ||
direction == BlurRenderer::BlurDirectionBoth)
{
if (tilt_shift == 1.0)
ss << "const float stepX = TextureStepX;" << std::endl;
else
ss << "float stepX = TextureStepX * abs(TiltShift - TextureCoord.y) / abs(1.0 - TiltShift);" << std::endl;
}
if (direction == BlurRenderer::BlurDirectionVertical ||
direction == BlurRenderer::BlurDirectionBoth)
{
if (tilt_shift == 1.0)
ss << "const float stepY = TextureStepY;" << std::endl;
else
ss << "float stepY = TextureStepY * abs(TiltShift - TextureCoord.y) / abs(1.0 - TiltShift);" << std::endl;
}
ss << "result = " << std::endl;
if (direction == BlurRenderer::BlurDirectionHorizontal) {
for (unsigned int i = 0; i < side; i++) {
int offset = static_cast<int>(i - radius);
ss << "texture2D(Texture0, TextureCoord + vec2(" <<
offset << ".0 * stepX, 0.0)) * Kernel" <<
std::abs(offset) << " +" << std::endl;
}
ss << "0.0 ;" << std::endl;
}
else if (direction == BlurRenderer::BlurDirectionVertical) {
for (unsigned int i = 0; i < side; i++) {
int offset = static_cast<int>(i - radius);
ss << "texture2D(Texture0, TextureCoord + vec2(0.0, " <<
offset << ".0 * stepY)) * Kernel" <<
std::abs(offset) << " +" << std::endl;
}
ss << "0.0 ;" << std::endl;
}
else if (direction == BlurRenderer::BlurDirectionBoth) {
for (unsigned int i = 0; i < side; i++) {
int ioffset = static_cast<int>(i - radius);
for (unsigned int j = 0; j < side; j++) {
int joffset = static_cast<int>(j - radius);
ss << "texture2D(Texture0, TextureCoord + vec2(" <<
ioffset << ".0 * stepX, " <<
joffset << ".0 * stepY))" <<
" * Kernel" << std::abs(ioffset) <<
" * Kernel" << std::abs(joffset) << " +" << std::endl;
}
}
ss << " 0.0;" << std::endl;
}
frg_source.replace("$CONVOLUTION$", ss.str());
}