Bake derivative

This commit is contained in:
luboslenco
2019-12-08 00:08:09 +01:00
parent 2f238c89c3
commit ae6baefd9b
4 changed files with 36 additions and 17 deletions
+13 -4
View File
@@ -79,17 +79,26 @@ class MakeBake {
frag.write('float res = distance(wpos0, wposition) * 10.0;');
frag.write('fragColor[0] = vec4(res, res, res, 1.0);');
}
else if (UITrait.inst.bakeType == 5) { // Position
else if (UITrait.inst.bakeType == 5) { // Derivative
frag.add_uniform('sampler2D texpaint_undo', '_texpaint_undo'); // Baked height
frag.write('vec2 texDx = dFdx(texCoord);');
frag.write('vec2 texDy = dFdy(texCoord);');
frag.write('float h0 = textureLod(texpaint_undo, texCoord, 0.0).r * 100;');
frag.write('float h1 = textureLod(texpaint_undo, texCoord + texDx, 0.0).r * 100;');
frag.write('float h2 = textureLod(texpaint_undo, texCoord + texDy, 0.0).r * 100;');
frag.write('fragColor[0] = vec4((h1 - h0) * 0.5 + 0.5, (h2 - h0) * 0.5 + 0.5, 0.0, 1.0);');
}
else if (UITrait.inst.bakeType == 6) { // Position
frag.wposition = true;
frag.write('fragColor[0] = vec4(wposition * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);');
if (UITrait.inst.bakeUpAxis == 1) { // Y up
frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);');
}
}
else if (UITrait.inst.bakeType == 6) { // TexCoord
else if (UITrait.inst.bakeType == 7) { // TexCoord
frag.write('fragColor[0] = vec4(texCoord.xy, 0.0, 1.0);');
}
else if (UITrait.inst.bakeType == 7) { // Material ID
else if (UITrait.inst.bakeType == 8) { // Material ID
frag.add_uniform('sampler2D texpaint_nor_undo', '_texpaint_nor_undo');
frag.write('float sample_matid = textureLod(texpaint_nor_undo, texCoord, 0.0).a + 1.0 / 255.0;');
frag.write('float matid_r = fract(sin(dot(vec2(sample_matid, sample_matid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);');
@@ -97,7 +106,7 @@ class MakeBake {
frag.write('float matid_b = fract(sin(dot(vec2(sample_matid, sample_matid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);');
frag.write('fragColor[0] = vec4(matid_r, matid_g, matid_b, 1.0);');
}
else if (UITrait.inst.bakeType == 8) { // Object ID
else if (UITrait.inst.bakeType == 9) { // Object ID
frag.add_uniform('float objectId', '_objectId');
frag.write('float obid = objectId + 1.0 / 255.0;');
frag.write('float id_r = fract(sin(dot(vec2(obid, obid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);');