本文整理汇总了C++中GrGLSLFPFragmentBuilder::fragmentPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ GrGLSLFPFragmentBuilder::fragmentPosition方法的具体用法?C++ GrGLSLFPFragmentBuilder::fragmentPosition怎么用?C++ GrGLSLFPFragmentBuilder::fragmentPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrGLSLFPFragmentBuilder
的用法示例。
在下文中一共展示了GrGLSLFPFragmentBuilder::fragmentPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitCode
void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
const char *edgeArrayName;
fEdgeUniform = args.fUniformHandler->addUniformArray(kFragment_GrShaderFlag,
kVec3f_GrSLType,
kDefault_GrSLPrecision,
"edges",
cpe.getEdgeCount(),
&edgeArrayName);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
fragBuilder->codeAppend("\t\tfloat edge;\n");
const char* fragmentPos = fragBuilder->fragmentPosition();
for (int i = 0; i < cpe.getEdgeCount(); ++i) {
fragBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n",
edgeArrayName, i, fragmentPos, fragmentPos);
if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) {
fragBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n");
} else {
fragBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n");
}
fragBuilder->codeAppend("\t\talpha *= edge;\n");
}
if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
fragBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
}
fragBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
(GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
示例2: emitCode
void GLDitherEffect::emitCode(EmitArgs& args) {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Generate a random number based on the fragment position. For this
// random number generator, we use the "GLSL rand" function
// that seems to be floating around on the internet. It works under
// the assumption that sin(<big number>) oscillates with high frequency
// and sampling it will generate "randomness". Since we're using this
// for rendering and not cryptography it should be OK.
// For each channel c, add the random offset to the pixel to either bump
// it up or let it remain constant during quantization.
fragBuilder->codeAppendf("\t\tfloat r = "
"fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758.5453);\n",
fragBuilder->fragmentPosition());
fragBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n",
args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_str());
}
示例3: emitCode
void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) {
const char *dataName;
// The data is formatted as:
// x,y - the center of the circle
// z - the distance at which the intensity starts falling off (e.g., the start of the table)
// w - the inverse of the profile texture size
fDataUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"data",
&dataName);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const char *fragmentPos = fragBuilder->fragmentPosition();
if (args.fInputColor) {
fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor);
} else {
fragBuilder->codeAppendf("vec4 src=vec4(1);");
}
// We just want to compute "length(vec) - %s.z + 0.5) * %s.w" but need to rearrange
// for precision
fragBuilder->codeAppendf("vec2 vec = vec2( (%s.x - %s.x) * %s.w , (%s.y - %s.y) * %s.w );",
fragmentPos, dataName, dataName,
fragmentPos, dataName, dataName);
fragBuilder->codeAppendf("float dist = length(vec) + ( 0.5 - %s.z ) * %s.w;",
dataName, dataName);
fragBuilder->codeAppendf("float intensity = ");
fragBuilder->appendTextureLookup(args.fTexSamplers[0], "vec2(dist, 0.5)");
fragBuilder->codeAppend(".a;");
fragBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor );
}