Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Side by Side Diff: src/effects/SkGaussianEdgeShader.cpp

Issue 2328263004: Fix GaussianEdgeShader GLSL code (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGaussianEdgeShader.h" 8 #include "SkGaussianEdgeShader.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 public: 79 public:
80 GLSLGaussianEdgeFP(bool largerBlur) : fLargerBlur(largerBlur) {} 80 GLSLGaussianEdgeFP(bool largerBlur) : fLargerBlur(largerBlur) {}
81 81
82 void emitCode(EmitArgs& args) override { 82 void emitCode(EmitArgs& args) override {
83 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 83 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
84 84
85 if (!args.fGpImplementsDistanceVector) { 85 if (!args.fGpImplementsDistanceVector) {
86 fragBuilder->codeAppendf("// GP does not implement fsDistanceVec tor - " 86 fragBuilder->codeAppendf("// GP does not implement fsDistanceVec tor - "
87 " returning grey in GLSLGaussianEdgeFP\ n"); 87 " returning grey in GLSLGaussianEdgeFP\ n");
88 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); 88 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor);
89 fragBuilder->codeAppendf("%s = vec4(0, 0, 0, color.r);", args.fO utputColor); 89 fragBuilder->codeAppendf("%s = vec4(0.0, 0.0, 0.0, color.r);", a rgs.fOutputColor);
90 } else if (fLargerBlur) { 90 } else if (fLargerBlur) {
91 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); 91 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor);
92 fragBuilder->codeAppend("float radius = color.r*256*64 + color.g *64;"); 92 fragBuilder->codeAppend("float radius = color.r*256.0*64.0 + col or.g*64.0;");
93 fragBuilder->codeAppend("float pad = color.b*64;"); 93 fragBuilder->codeAppend("float pad = color.b*64.0;");
94 94
95 fragBuilder->codeAppendf("float factor = 1 - clamp((%s.z - pad)/ radius, 0, 1);", 95 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad )/radius, 0.0, 1.0);",
egdaniel 2016/09/12 17:07:00 100 chars
96 fragBuilder->distanceVectorName()); 96 fragBuilder->distanceVectorName());
97 fragBuilder->codeAppend("factor = exp(-factor * factor * 4) - 0. 018;"); 97 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.018;");
98 fragBuilder->codeAppendf("%s = factor*vec4(0, 0, 0, color.a);", 98 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color. a);",
99 args.fOutputColor); 99 args.fOutputColor);
100 } else { 100 } else {
101 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); 101 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor);
102 fragBuilder->codeAppend("float radius = color.g*64;"); 102 fragBuilder->codeAppend("float radius = color.g*64.0;");
103 fragBuilder->codeAppend("float pad = color.b*64;"); 103 fragBuilder->codeAppend("float pad = color.b*64.0;");
104 104
105 fragBuilder->codeAppendf("float factor = 1 - clamp((%s.z - pad)/ radius, 0, 1);", 105 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad )/radius, 0.0, 1.0);",
egdaniel 2016/09/12 17:07:00 100chars
106 fragBuilder->distanceVectorName()); 106 fragBuilder->distanceVectorName());
107 fragBuilder->codeAppend("factor = exp(-factor * factor * 4) - 0. 018;"); 107 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.018;");
108 fragBuilder->codeAppendf("%s = factor*vec4(0, 0, 0, color.r);", 108 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color. r);",
109 args.fOutputColor); 109 args.fOutputColor);
110 } 110 }
111 } 111 }
112 112
113 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 113 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
114 GrProcessorKeyBuilder* b) { 114 GrProcessorKeyBuilder* b) {
115 const GaussianEdgeFP& gefp = proc.cast<GaussianEdgeFP>(); 115 const GaussianEdgeFP& gefp = proc.cast<GaussianEdgeFP>();
116 b->add32(gefp.fLargerBlur ? 0x1 : 0x0); 116 b->add32(gefp.fLargerBlur ? 0x1 : 0x0);
117 } 117 }
118 118
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return sk_make_sp<SkGaussianEdgeShaderImpl>(largerBlur); 177 return sk_make_sp<SkGaussianEdgeShaderImpl>(largerBlur);
178 } 178 }
179 179
180 /////////////////////////////////////////////////////////////////////////////// 180 ///////////////////////////////////////////////////////////////////////////////
181 181
182 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) 182 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader)
183 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) 183 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl)
184 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 184 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
185 185
186 /////////////////////////////////////////////////////////////////////////////// 186 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698