Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkShadowShader.h" | 10 #include "SkShadowShader.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 const SkShadowParams& params, | 111 const SkShadowParams& params, |
| 112 GrContext* context) { | 112 GrContext* context) { |
| 113 | 113 |
| 114 fAmbientColor = lights->ambientLightColor(); | 114 fAmbientColor = lights->ambientLightColor(); |
| 115 | 115 |
| 116 fNumNonAmbLights = 0; // count of non-ambient lights | 116 fNumNonAmbLights = 0; // count of non-ambient lights |
| 117 for (int i = 0; i < lights->numLights(); ++i) { | 117 for (int i = 0; i < lights->numLights(); ++i) { |
| 118 if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) { | 118 if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) { |
| 119 fLightColor[fNumNonAmbLights] = lights->light(i).color(); | 119 fLightColor[fNumNonAmbLights] = lights->light(i).color(); |
| 120 | 120 |
| 121 if (SkLights::Light::kDirectional_LightType == lights->light(i). type()) { | 121 if (SkLights::Light::kPoint_LightType == lights->light(i).type() ) { |
| 122 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).pos(); | |
| 123 fLightIntensity[fNumNonAmbLights] = lights->light(i).intensi ty(); | |
|
jvanverth1
2016/08/30 15:55:42
Suggestion: allow SkLight to have color and intens
vjiaoblack
2016/08/30 16:52:18
Done.
| |
| 124 } else { | |
| 122 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).dir(); | 125 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).dir(); |
| 123 fLightIntensity[fNumNonAmbLights] = 0.0f; | 126 fLightIntensity[fNumNonAmbLights] = 0.0f; |
| 124 } else if (SkLights::Light::kPoint_LightType == lights->light(i) .type()) { | |
| 125 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).pos(); | |
| 126 fLightIntensity[fNumNonAmbLights] = lights->light(i).intensi ty(); | |
| 127 } | 127 } |
| 128 | 128 |
| 129 fIsPointLight[fNumNonAmbLights] = | 129 fIsPointLight[fNumNonAmbLights] = |
| 130 SkLights::Light::kPoint_LightType == lights->light(i).ty pe(); | 130 SkLights::Light::kPoint_LightType == lights->light(i).ty pe(); |
| 131 | 131 |
| 132 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); | 132 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); |
| 133 | 133 |
| 134 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture* | 134 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture* |
| 135 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context, | 135 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context, |
| 136 GrTextureParams::Clam pNoFilter(), | 136 GrTextureParams::Clam pNoFilter(), |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 167 SkASSERT(shadowFP.fNumNonAmbLights <= SkShadowShader::kMaxNonAmbient Lights); | 167 SkASSERT(shadowFP.fNumNonAmbLights <= SkShadowShader::kMaxNonAmbient Lights); |
| 168 | 168 |
| 169 // add uniforms | 169 // add uniforms |
| 170 int32_t numLights = shadowFP.fNumNonAmbLights; | 170 int32_t numLights = shadowFP.fNumNonAmbLights; |
| 171 SkASSERT(numLights <= SkShadowShader::kMaxNonAmbientLights); | 171 SkASSERT(numLights <= SkShadowShader::kMaxNonAmbientLights); |
| 172 | 172 |
| 173 int blurAlgorithm = shadowFP.fShadowParams.fType; | 173 int blurAlgorithm = shadowFP.fShadowParams.fType; |
| 174 | 174 |
| 175 const char* lightDirOrPosUniName[SkShadowShader::kMaxNonAmbientLight s] = {nullptr}; | 175 const char* lightDirOrPosUniName[SkShadowShader::kMaxNonAmbientLight s] = {nullptr}; |
| 176 const char* lightColorUniName[SkShadowShader::kMaxNonAmbientLights] = {nullptr}; | 176 const char* lightColorUniName[SkShadowShader::kMaxNonAmbientLights] = {nullptr}; |
| 177 const char* lightIntensityUniName[SkShadowShader::kMaxNonAmbientLigh ts] = {nullptr}; | 177 const char* lightIntensityUniName[SkShadowShader::kMaxNonAmbientLigh ts] = |
| 178 {nullptr}; | |
|
jvanverth1
2016/08/30 15:55:42
Why is this on a different line?
vjiaoblack
2016/08/30 16:52:18
Done.
vjiaoblack
2016/08/30 16:52:18
Acknowledged.
| |
| 179 | |
| 180 const char* ambientColorUniName = nullptr; | |
| 178 | 181 |
| 179 const char* depthMapWidthUniName[SkShadowShader::kMaxNonAmbientLight s] = {nullptr}; | 182 const char* depthMapWidthUniName[SkShadowShader::kMaxNonAmbientLight s] = {nullptr}; |
| 180 const char* depthMapHeightUniName[SkShadowShader::kMaxNonAmbientLigh ts] = {nullptr}; | 183 const char* depthMapHeightUniName[SkShadowShader::kMaxNonAmbientLigh ts] = {nullptr}; |
| 184 const char* widthUniName = nullptr; // dimensions of povDepth | |
| 185 const char* heightUniName = nullptr; | |
| 181 | 186 |
| 187 const char* shBiasUniName = nullptr; | |
| 188 const char* minVarianceUniName = nullptr; | |
| 189 | |
| 190 // setting uniforms | |
| 182 for (int i = 0; i < shadowFP.fNumNonAmbLights; i++) { | 191 for (int i = 0; i < shadowFP.fNumNonAmbLights; i++) { |
| 183 SkString lightDirOrPosUniNameStr("lightDir"); | 192 SkString lightDirOrPosUniNameStr("lightDir"); |
| 184 lightDirOrPosUniNameStr.appendf("%d", i); | 193 lightDirOrPosUniNameStr.appendf("%d", i); |
| 185 SkString lightColorUniNameStr("lightColor"); | 194 SkString lightColorUniNameStr("lightColor"); |
| 186 lightColorUniNameStr.appendf("%d", i); | 195 lightColorUniNameStr.appendf("%d", i); |
| 187 SkString lightIntensityUniNameStr("lightIntensity"); | 196 SkString lightIntensityUniNameStr("lightIntensity"); |
| 188 lightIntensityUniNameStr.appendf("%d", i); | 197 lightIntensityUniNameStr.appendf("%d", i); |
| 189 | 198 |
| 190 SkString depthMapWidthUniNameStr("dmapWidth"); | 199 SkString depthMapWidthUniNameStr("dmapWidth"); |
| 191 depthMapWidthUniNameStr.appendf("%d", i); | 200 depthMapWidthUniNameStr.appendf("%d", i); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 214 kDefault_GrSLPrecision, | 223 kDefault_GrSLPrecision, |
| 215 depthMapWidthUniNameStr.c_str (), | 224 depthMapWidthUniNameStr.c_str (), |
| 216 &depthMapWidthUniName[i]); | 225 &depthMapWidthUniName[i]); |
| 217 fDepthMapHeightUni[i] = uniformHandler->addUniform(kFragment_GrS haderFlag, | 226 fDepthMapHeightUni[i] = uniformHandler->addUniform(kFragment_GrS haderFlag, |
| 218 kInt_GrSLType, | 227 kInt_GrSLType, |
| 219 kDefault_GrSLPrecision, | 228 kDefault_GrSLPrecision, |
| 220 depthMapHeightUniNameStr.c_st r(), | 229 depthMapHeightUniNameStr.c_st r(), |
| 221 &depthMapHeightUniName[i]); | 230 &depthMapHeightUniName[i]); |
| 222 } | 231 } |
| 223 | 232 |
| 224 const char* shBiasUniName = nullptr; | |
| 225 const char* minVarianceUniName = nullptr; | |
| 226 | |
| 227 fBiasingConstantUni = uniformHandler->addUniform(kFragment_GrShaderF lag, | 233 fBiasingConstantUni = uniformHandler->addUniform(kFragment_GrShaderF lag, |
| 228 kFloat_GrSLType, | 234 kFloat_GrSLType, |
| 229 kDefault_GrSLPrecis ion, | 235 kDefault_GrSLPrecis ion, |
| 230 "shadowBias", &shBi asUniName); | 236 "shadowBias", &shBi asUniName); |
| 231 fMinVarianceUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 237 fMinVarianceUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 232 kFloat_GrSLType, | 238 kFloat_GrSLType, |
| 233 kDefault_GrSLPrecision, | 239 kDefault_GrSLPrecision, |
| 234 "minVariance", &minVari anceUniName); | 240 "minVariance", &minVari anceUniName); |
| 235 | 241 |
| 236 const char* widthUniName = nullptr; | |
| 237 const char* heightUniName = nullptr; | |
| 238 | |
| 239 fWidthUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 242 fWidthUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 240 kInt_GrSLType, | 243 kInt_GrSLType, |
| 241 kDefault_GrSLPrecision, | 244 kDefault_GrSLPrecision, |
| 242 "width", &widthUniName); | 245 "width", &widthUniName); |
| 243 fHeightUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 246 fHeightUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 244 kInt_GrSLType, | 247 kInt_GrSLType, |
| 245 kDefault_GrSLPrecision, | 248 kDefault_GrSLPrecision, |
| 246 "height", &heightUniName); | 249 "height", &heightUniName); |
| 247 | 250 |
| 251 fAmbientColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag , | |
| 252 kVec3f_GrSLType, kDefa ult_GrSLPrecision, | |
| 253 "AmbientColor", &ambie ntColorUniName); | |
| 254 | |
| 255 SkString povDepthSampler("_povDepth"); | |
| 248 SkString povDepth("povDepth"); | 256 SkString povDepth("povDepth"); |
| 249 this->emitChild(0, nullptr, &povDepth, args); | 257 this->emitChild(0, nullptr, &povDepthSampler, args); |
| 258 fragBuilder->codeAppendf("vec4 %s = %s;", povDepth.c_str(), povDepth Sampler.c_str()); | |
| 250 | 259 |
| 260 SkString diffuseColorSampler("_inDiffuseColor"); | |
| 251 SkString diffuseColor("inDiffuseColor"); | 261 SkString diffuseColor("inDiffuseColor"); |
| 252 this->emitChild(1, nullptr, &diffuseColor, args); | 262 this->emitChild(1, nullptr, &diffuseColorSampler, args); |
| 263 fragBuilder->codeAppendf("vec4 %s = %s;", diffuseColor.c_str(), | |
| 264 diffuseColorSampler.c_str()); | |
| 253 | 265 |
| 254 SkString depthMaps[SkShadowShader::kMaxNonAmbientLights]; | 266 SkString depthMaps[SkShadowShader::kMaxNonAmbientLights]; |
| 255 | 267 |
| 268 fragBuilder->codeAppendf("vec4 resultDiffuseColor = %s;", diffuseCol or.c_str()); | |
| 269 fragBuilder->codeAppend ("vec3 totalLightColor = vec3(0);"); | |
| 270 | |
| 271 // probability that a fragment is lit. For each light, we multiply t his by the | |
| 272 // light's color to get its contribution to totalLightColor. | |
| 273 fragBuilder->codeAppend ("float lightProbability;"); | |
| 274 | |
| 275 // coordinates of current fragment in world space | |
| 276 fragBuilder->codeAppend ("vec3 worldCor;"); | |
| 277 | |
| 256 // Multiply by 255 to transform from sampler coordinates to world | 278 // Multiply by 255 to transform from sampler coordinates to world |
| 257 // coordinates (since 1 channel is 0xFF) | 279 // coordinates (since 1 channel is 0xFF) |
| 258 fragBuilder->codeAppendf("vec3 worldCor = vec3(vMatrixCoord_0_1_Stag e0 * " | 280 fragBuilder->codeAppendf("worldCor = vec3(vMatrixCoord_0_1_Stage0 * " |
|
jvanverth1
2016/08/30 15:55:42
You might want to put a note in the header that th
vjiaoblack
2016/08/30 16:52:18
Done.
Know of any way to do this in a non hacky w
| |
| 259 "vec2(%s, %s), %s.b * 255); ", | 281 "vec2(%s, %s), %s.b * 255);", |
| 260 widthUniName, heightUniName, povDepth.c_str ()); | 282 widthUniName, heightUniName, povDepth.c_str ()); |
| 261 | 283 |
| 262 // Applies the offset indexing that goes from our view space into th e light's space. | 284 // Applies the offset indexing that goes from our view space into th e light's space. |
| 263 for (int i = 0; i < shadowFP.fNumNonAmbLights; i++) { | 285 for (int i = 0; i < shadowFP.fNumNonAmbLights; i++) { |
| 264 SkString povCoord("povCoord"); | 286 SkString povCoord("povCoord"); |
| 265 povCoord.appendf("%d", i); | 287 povCoord.appendf("%d", i); |
| 266 | 288 |
| 267 // vMatrixCoord_0_1_Stage0 is the texture sampler coordinates. | 289 // vMatrixCoord_0_1_Stage0 is the texture sampler coordinates. |
|
jvanverth1
2016/08/30 15:55:42
This comment should move up to where you first use
vjiaoblack
2016/08/30 16:52:18
Done.
| |
| 268 // povDepth.b * 255 scales it to 0 - 255, bringing it to world s pace, | 290 // povDepth.b * 255 scales it to 0 - 255, bringing it to world s pace, |
| 269 // and the / vec2(width, height) brings it back to a sampler coo rdinate | 291 // and the / vec2(width, height) brings it back to a sampler coo rdinate |
| 270 SkString offset("offset"); | 292 SkString offset("offset"); |
| 271 offset.appendf("%d", i); | 293 offset.appendf("%d", i); |
| 272 | 294 |
| 273 SkString scaleVec("scaleVec"); | 295 SkString scaleVec("scaleVec"); |
| 274 scaleVec.appendf("%d", i); | 296 scaleVec.appendf("%d", i); |
| 275 | 297 |
| 276 SkString scaleOffsetVec("scaleOffsetVec"); | |
| 277 scaleOffsetVec.appendf("%d", i); | |
| 278 | |
| 279 fragBuilder->codeAppendf("vec2 %s;", offset.c_str()); | 298 fragBuilder->codeAppendf("vec2 %s;", offset.c_str()); |
| 280 | 299 |
| 300 // note that we flip the y-coord of the offset and then later ad d | |
| 301 // a value just to the y-coord of povCoord. This is to account f or | |
| 302 // the shifted origins from switching from raster into GPU. | |
| 281 if (shadowFP.fIsPointLight[i]) { | 303 if (shadowFP.fIsPointLight[i]) { |
| 282 fragBuilder->codeAppendf("vec3 fragToLight%d = %s - worldCor ;", | 304 fragBuilder->codeAppendf("vec3 fragToLight%d = %s - worldCor ;", |
| 283 i, lightDirOrPosUniName[i]); | 305 i, lightDirOrPosUniName[i]); |
| 284 fragBuilder->codeAppendf("float distsq%d = dot(fragToLight%d , fragToLight%d);" | 306 fragBuilder->codeAppendf("float distsq%d = dot(fragToLight%d , fragToLight%d);" |
| 285 "fragToLight%d = normalize(fragToLi ght%d);", | 307 "fragToLight%d = normalize(fragToLi ght%d);", |
| 286 i, i, i, i, i); | 308 i, i, i, i, i); |
| 287 fragBuilder->codeAppendf("%s = -vec2(%s.x - worldCor.x, worl dCor.y - %s.y)*" | 309 fragBuilder->codeAppendf("%s = vec2(worldCor.x - %s.x, %s.y - worldCor.y) * " |
| 288 "(povDepth.b) / vec2(%s, %s) ;", | 310 "povDepth.b;", |
| 289 offset.c_str(), lightDirOrPosUniNam e[i], | 311 offset.c_str(), lightDirOrPosUniNam e[i], |
| 290 lightDirOrPosUniName[i], | 312 lightDirOrPosUniName[i]); |
| 291 widthUniName, heightUniName); | |
| 292 } else { | 313 } else { |
| 293 fragBuilder->codeAppendf("%s = vec2(%s) * povDepth.b * 255 / vec2(%s, %s);", | 314 fragBuilder->codeAppendf("%s = vec2(%s) * povDepth.b * vec2( 255.0, -255.0);", |
| 294 offset.c_str(), lightDirOrPosUniNam e[i], | 315 offset.c_str(), lightDirOrPosUniNam e[i]); |
| 295 widthUniName, heightUniName); | |
| 296 } | 316 } |
| 297 fragBuilder->codeAppendf("vec2 %s = (vec2(%s, %s) / vec2(%s, %s) );", | 317 fragBuilder->codeAppendf("vec2 %s = (vec2(%s, %s) *" |
| 298 scaleVec.c_str(), | 318 "vMatrixCoord_0_1_Stage0 +" |
| 319 "vec2(0,%s - %s)" | |
| 320 " + " | |
| 321 "%s) / vec2(%s, %s);", | |
| 322 povCoord.c_str(), | |
| 299 widthUniName, heightUniName, | 323 widthUniName, heightUniName, |
| 324 depthMapHeightUniName[i], heightUniName , | |
| 325 offset.c_str(), | |
| 300 depthMapWidthUniName[i], depthMapHeight UniName[i]); | 326 depthMapWidthUniName[i], depthMapHeight UniName[i]); |
| 301 | 327 |
| 302 fragBuilder->codeAppendf("vec2 %s = 1 - %s;\n", | |
| 303 scaleOffsetVec.c_str(), | |
| 304 scaleVec.c_str()); | |
| 305 | |
| 306 fragBuilder->codeAppendf("vec2 %s = (vMatrixCoord_0_1_Stage0 + " | |
| 307 "vec2(%s.x, 0 - %s.y)) " | |
| 308 " * %s + vec2(0,1) * %s;", | |
| 309 povCoord.c_str(), offset.c_str(), offse t.c_str(), | |
| 310 scaleVec.c_str(), scaleOffsetVec.c_str( )); | |
| 311 | |
| 312 fragBuilder->appendTextureLookup(&depthMaps[i], args.fTexSampler s[i], | 328 fragBuilder->appendTextureLookup(&depthMaps[i], args.fTexSampler s[i], |
| 313 povCoord.c_str(), | 329 povCoord.c_str(), |
| 314 kVec2f_GrSLType); | 330 kVec2f_GrSLType); |
| 315 | 331 |
| 316 } | 332 } |
| 317 | 333 |
| 318 const char* ambientColorUniName = nullptr; | 334 // helper variables for calculating shadowing |
| 319 fAmbientColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag , | |
| 320 kVec3f_GrSLType, kDefa ult_GrSLPrecision, | |
| 321 "AmbientColor", &ambie ntColorUniName); | |
| 322 | 335 |
| 323 fragBuilder->codeAppendf("vec4 resultDiffuseColor = %s;", diffuseCol or.c_str()); | 336 // variance of depth at this fragment in the context of surrounding area |
| 337 // (area size and weighting dependent on blur size and type) | |
| 338 fragBuilder->codeAppendf("float variance;"); | |
| 324 | 339 |
| 325 SkString totalLightColor("totalLightColor"); | 340 // the difference in depth between the user POV and light POV. |
| 326 fragBuilder->codeAppendf("vec3 %s = vec3(0,0,0);", totalLightColor.c _str()); | |
| 327 | |
| 328 fragBuilder->codeAppendf("float lightProbability;"); | |
| 329 fragBuilder->codeAppendf("float variance;"); | |
| 330 fragBuilder->codeAppendf("float d;"); | 341 fragBuilder->codeAppendf("float d;"); |
| 331 | 342 |
| 343 // add up light contributions from all lights to totalLightColor | |
| 332 for (int i = 0; i < numLights; i++) { | 344 for (int i = 0; i < numLights; i++) { |
| 333 if (!shadowFP.isPointLight(i)) { | 345 if (!shadowFP.isPointLight(i)) { |
| 334 fragBuilder->codeAppendf("lightProbability = 1;"); | 346 fragBuilder->codeAppendf("lightProbability = 1;"); |
| 335 | 347 |
| 336 // 1/512 is less than half a pixel; imperceptible | 348 // 1/512 == .00195... is less than half a pixel; imperceptib le |
| 337 fragBuilder->codeAppendf("if (%s.b <= %s.b + 1/512) {", | 349 fragBuilder->codeAppendf("if (%s.b <= %s.b + .001953125) {", |
| 338 povDepth.c_str(), depthMaps[i].c_st r()); | 350 povDepth.c_str(), depthMaps[i].c_st r()); |
| 339 if (blurAlgorithm == SkShadowParams::kVariance_ShadowType) { | 351 if (blurAlgorithm == SkShadowParams::kVariance_ShadowType) { |
| 340 fragBuilder->codeAppendf("vec2 moments%d = vec2(%s.b * 2 55," | 352 // We mess with depth and depth^2 in their given scales. |
|
jvanverth1
2016/08/30 15:55:42
Since you reverted the variance change, do you nee
vjiaoblack
2016/08/30 16:52:18
I think this is fine. Everything also works as exp
| |
| 341 "%s.g * 2 55 * 256 );", | 353 // (i.e. between 0 and 1) |
| 354 fragBuilder->codeAppendf("vec2 moments%d = vec2(%s.b, %s .g);", | |
| 342 i, depthMaps[i].c_str(), depthM aps[i].c_str()); | 355 i, depthMaps[i].c_str(), depthM aps[i].c_str()); |
| 343 | 356 |
| 344 // variance biasing lessens light bleeding | 357 // variance biasing lessens light bleeding |
| 345 fragBuilder->codeAppendf("variance = max(moments%d.y - " | 358 fragBuilder->codeAppendf("variance = max(moments%d.y - " |
| 346 "(moments%d.x * moments%d.x)," | 359 "(moments%d.x * moments%d.x)," |
| 347 "%s);", i, i, i, | 360 "%s);", i, i, i, |
| 348 minVarianceUniName); | 361 minVarianceUniName); |
| 349 | 362 |
| 350 fragBuilder->codeAppendf("d = (%s.b * 255) - moments%d.x ;", | 363 fragBuilder->codeAppendf("d = (%s.b) - moments%d.x;", |
| 351 povDepth.c_str(), i); | 364 povDepth.c_str(), i); |
| 352 fragBuilder->codeAppendf("lightProbability = " | 365 fragBuilder->codeAppendf("lightProbability = " |
| 353 "(variance / (variance + d * d));"); | 366 "(variance / (variance + d * d));"); |
| 354 | 367 |
| 355 SkString clamp("clamp"); | 368 SkString clamp("clamp"); |
| 356 clamp.appendf("%d", i); | 369 clamp.appendf("%d", i); |
| 357 | 370 |
| 358 // choosing between light artifacts or correct shape sha dows | 371 // choosing between light artifacts or correct shape sha dows |
| 359 // linstep | 372 // linstep |
| 360 fragBuilder->codeAppendf("float %s = clamp((lightProbabi lity - %s) /" | 373 fragBuilder->codeAppendf("float %s = clamp((lightProbabi lity - %s) /" |
| 361 "(1 - %s), 0, 1);", | 374 "(1 - %s), 0, 1);", |
| 362 clamp.c_str(), shBiasUniName, s hBiasUniName); | 375 clamp.c_str(), shBiasUniName, s hBiasUniName); |
| 363 | 376 |
| 364 fragBuilder->codeAppendf("lightProbability = %s;", clamp .c_str()); | 377 fragBuilder->codeAppendf("lightProbability = %s;", clamp .c_str()); |
| 365 } else { | 378 } else { |
| 366 fragBuilder->codeAppendf("if (%s.b >= %s.b) {", | 379 fragBuilder->codeAppendf("if (%s.b >= %s.b) {", |
| 367 povDepth.c_str(), depthMaps[i]. c_str()); | 380 povDepth.c_str(), depthMaps[i]. c_str()); |
| 368 fragBuilder->codeAppendf("lightProbability = 1;"); | 381 fragBuilder->codeAppendf("lightProbability = 1;"); |
| 369 fragBuilder->codeAppendf("} else { lightProbability = 0; }"); | 382 fragBuilder->codeAppendf("} else { lightProbability = 0; }"); |
| 370 } | 383 } |
| 371 | 384 |
| 372 // VSM: The curved shadows near plane edges are artifacts fr om blurring | 385 // VSM: The curved shadows near plane edges are artifacts fr om blurring |
| 373 fragBuilder->codeAppendf("}"); | 386 fragBuilder->codeAppendf("}"); |
| 374 fragBuilder->codeAppendf("%s += dot(vec3(0,0,1), %s) * %s * " | 387 fragBuilder->codeAppendf("totalLightColor += %s.z * %s * " |
| 375 "lightProbability;", | 388 "lightProbabilit y;", |
| 376 totalLightColor.c_str(), | |
| 377 lightDirOrPosUniName[i], | 389 lightDirOrPosUniName[i], |
| 378 lightColorUniName[i]); | 390 lightColorUniName[i]); |
| 379 } else { | 391 } else { |
| 380 // fragToLight%d.z is equal to the fragToLight dot the surfa ce normal. | 392 // fragToLight%d.z is equal to the fragToLight dot the surfa ce normal. |
| 381 fragBuilder->codeAppendf("%s += max(fragToLight%d.z, 0) * %s /" | 393 fragBuilder->codeAppendf("totalLightColor += max(fragToLight %d.z, 0) * " |
| 382 "(1 + distsq%d / (%s * %s));" , | 394 "%s * %s * 2 /" |
|
jvanverth1
2016/08/30 15:55:42
Why multiply by 2?
vjiaoblack
2016/08/30 16:52:18
Done.
| |
| 383 totalLightColor.c_str(), i, | 395 "(1 + distsq%d); ", |
| 384 lightColorUniName[i], i, | 396 i, lightColorUniName[i], |
| 385 lightIntensityUniName[i], | 397 lightIntensityUniName[i], i); |
| 386 lightIntensityUniName[i]); | 398 |
| 399 | |
| 387 } | 400 } |
| 388 } | 401 } |
| 389 | 402 |
| 390 fragBuilder->codeAppendf("%s += %s;", totalLightColor.c_str(), ambie ntColorUniName); | 403 fragBuilder->codeAppendf("totalLightColor += %s;", ambientColorUniNa me); |
| 391 | 404 fragBuilder->codeAppendf("%s = resultDiffuseColor * vec4(totalLightC olor, 1);", |
| 392 fragBuilder->codeAppendf("resultDiffuseColor *= vec4(%s, 1);", | 405 args.fOutputColor); |
| 393 totalLightColor.c_str()); | |
| 394 | |
| 395 fragBuilder->codeAppendf("%s = resultDiffuseColor;", args.fOutputCol or); | |
| 396 } | 406 } |
| 397 | 407 |
| 398 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 408 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
| 399 GrProcessorKeyBuilder* b) { | 409 GrProcessorKeyBuilder* b) { |
| 400 const ShadowFP& shadowFP = proc.cast<ShadowFP>(); | 410 const ShadowFP& shadowFP = proc.cast<ShadowFP>(); |
| 401 b->add32(shadowFP.fNumNonAmbLights); | 411 b->add32(shadowFP.fNumNonAmbLights); |
| 402 int isPL = 0; | 412 int isPL = 0; |
| 403 for (int i = 0; i < SkShadowShader::kMaxNonAmbientLights; i++) { | 413 for (int i = 0; i < SkShadowShader::kMaxNonAmbientLights; i++) { |
| 404 isPL = isPL | ((shadowFP.fIsPointLight[i] ? 1 : 0) << i); | 414 isPL = isPL | ((shadowFP.fIsPointLight[i] ? 1 : 0) << i); |
| 405 } | 415 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 } | 453 } |
| 444 | 454 |
| 445 SkScalar biasingConstant = shadowFP.shadowParams().fBiasingConstant; | 455 SkScalar biasingConstant = shadowFP.shadowParams().fBiasingConstant; |
| 446 if (biasingConstant != fBiasingConstant) { | 456 if (biasingConstant != fBiasingConstant) { |
| 447 pdman.set1f(fBiasingConstantUni, biasingConstant); | 457 pdman.set1f(fBiasingConstantUni, biasingConstant); |
| 448 fBiasingConstant = biasingConstant; | 458 fBiasingConstant = biasingConstant; |
| 449 } | 459 } |
| 450 | 460 |
| 451 SkScalar minVariance = shadowFP.shadowParams().fMinVariance; | 461 SkScalar minVariance = shadowFP.shadowParams().fMinVariance; |
| 452 if (minVariance != fMinVariance) { | 462 if (minVariance != fMinVariance) { |
| 453 pdman.set1f(fMinVarianceUni, minVariance); | 463 pdman.set1f(fMinVarianceUni, minVariance / 65536.0f); |
|
jvanverth1
2016/08/30 15:55:42
Should this be reverted?
vjiaoblack
2016/08/30 16:52:18
What revert are you talking about?
| |
| 454 fMinVariance = minVariance; | 464 fMinVariance = minVariance / 65536.0f; |
| 455 } | 465 } |
| 456 | 466 |
| 457 int width = shadowFP.width(); | 467 int width = shadowFP.width(); |
| 458 if (width != fWidth) { | 468 if (width != fWidth) { |
| 459 pdman.set1i(fWidthUni, width); | 469 pdman.set1i(fWidthUni, width); |
| 460 fWidth = width; | 470 fWidth = width; |
| 461 } | 471 } |
| 462 int height = shadowFP.height(); | 472 int height = shadowFP.height(); |
| 463 if (height != fHeight) { | 473 if (height != fHeight) { |
| 464 pdman.set1i(fHeightUni, height); | 474 pdman.set1i(fHeightUni, height); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 | 846 |
| 837 /////////////////////////////////////////////////////////////////////////////// | 847 /////////////////////////////////////////////////////////////////////////////// |
| 838 | 848 |
| 839 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) | 849 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) |
| 840 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) | 850 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) |
| 841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 851 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 842 | 852 |
| 843 /////////////////////////////////////////////////////////////////////////////// | 853 /////////////////////////////////////////////////////////////////////////////// |
| 844 | 854 |
| 845 #endif | 855 #endif |
| OLD | NEW |