Improving height paint

This commit is contained in:
luboslenco
2019-05-31 12:28:27 +02:00
parent f1ba1fa011
commit 14599d5853
5 changed files with 35 additions and 7 deletions
+3 -2
View File
@@ -181,11 +181,12 @@ struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV
SPIRV_Cross_Output main(float4 pos : TEXCOORD1, float2 nor : TEXCOORD0, float2 tex : TEXCOORD2) {
SPIRV_Cross_Output stage_output;
stage_output.texCoord = tex;
float depth = gbufferD.SampleLevel(_gbufferD_sampler, mouse, 0).r;
float2 mouseinv = float2(mouse.x, 1.0 - mouse.y);
float depth = gbufferD.SampleLevel(_gbufferD_sampler, mouseinv, 0).r;
float4 wpos = float4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
wpos = mul(wpos, invVP);
wpos.xyz /= wpos.w;
float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, mouse, 0.0).rg;
float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, mouseinv, 0.0).rg;
float3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
+1
View File
@@ -55,6 +55,7 @@ class Layers {
g.begin();
iron.App.removeRender(initLayers);
UITrait.inst.layerPreviewDirty = true;
UITrait.inst.ddirty = 3;
}
+23 -5
View File
@@ -850,12 +850,18 @@ class MaterialBuilder {
// Height
// TODO: can cause TAA issues
if (heightUsed) {
#if (!kha_direct3d11) // TODO: unable to bind texpaint_pack to both vs and fs in d3d11
vert.write('float height = textureLod(texpaint_pack, tex, 0.0).a;');
var displaceStrength = UITrait.inst.displaceStrength * 0.1;
var displaceStrength = UITrait.inst.displaceStrength * 0.02;
vert.n = true;
vert.write('wposition += wnormal * height * $displaceStrength;');
#end
vert.write('float height = 0.0;');
var numLayers = 0;
for (l in UITrait.inst.layers) {
if (!l.visible) continue;
if (numLayers > 4) break;
numLayers++;
vert.add_uniform('sampler2D texpaint_pack_vert' + l.id, '_texpaint_pack_vert' + l.id);
vert.write('height += textureLod(texpaint_pack_vert' + l.id + ', tex, 0.0).a;');
}
vert.write('wposition += wnormal * vec3(height, height, height) * vec3($displaceStrength, $displaceStrength, $displaceStrength);');
}
//
@@ -1140,4 +1146,16 @@ class MaterialBuilder {
return con_mesh;
}
public static function make_voxel(data:iron.data.ShaderData.ShaderContext) {
// uniform float4x4 W;
// struct SPIRV_Cross_Input { float4 pos : TEXCOORD0; };
// struct SPIRV_Cross_Output { float4 svpos : SV_POSITION; };
// SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) {
// SPIRV_Cross_Output stage_output;
// stage_output.svpos.xyz = mul(float4(stage_input.pos.xyz, 1.0), W).xyz / float3(1, 1, 1);
// stage_output.svpos.w = 1.0;
// return stage_output;
// }
}
}
+4
View File
@@ -36,6 +36,10 @@ class MaterialParser {
m.shader.raw.contexts.push(sc.raw);
m.shader.contexts.push(sc);
UITrait.inst.ddirty = 2;
var sc:ShaderContext = null;
for (c in m.shader.contexts) if (c.raw.name == "voxel") { sc = c; break; }
MaterialBuilder.make_voxel(sc);
// });
}
+4
View File
@@ -142,6 +142,10 @@ class Uniforms {
var i = UITrait.inst.undoI - 1 < 0 ? App.C.undo_steps - 1 : UITrait.inst.undoI - 1;
return RenderPath.active.renderTargets.get("texpaint_pack_undo" + i).image;
}
else if (StringTools.startsWith(link, "_texpaint_pack_vert")) {
var tid = link.substr(19);
return RenderPath.active.renderTargets.get("texpaint_pack" + tid).image;
}
else if (link == "_texpaint_mask") {
return UITrait.inst.selectedLayer.texpaint_mask;
}