Bindable depth.
This commit is contained in:
parent
9431337efe
commit
a589a76250
|
@ -130,6 +130,23 @@ class ColorBufferNode(Node, CGPipelineTreeNode):
|
||||||
|
|
||||||
def free(self):
|
def free(self):
|
||||||
print("Removing node ", self, ", Goodbye!")
|
print("Removing node ", self, ", Goodbye!")
|
||||||
|
|
||||||
|
class DepthBufferNode(Node, CGPipelineTreeNode):
|
||||||
|
'''A custom node'''
|
||||||
|
bl_idname = 'DepthBufferNodeType'
|
||||||
|
bl_label = 'Depth Buffer'
|
||||||
|
bl_icon = 'SOUND'
|
||||||
|
|
||||||
|
def init(self, context):
|
||||||
|
self.inputs.new('NodeSocketShader', "Target")
|
||||||
|
|
||||||
|
self.outputs.new('NodeSocketShader', "Target")
|
||||||
|
|
||||||
|
def copy(self, node):
|
||||||
|
print("Copying from node ", node)
|
||||||
|
|
||||||
|
def free(self):
|
||||||
|
print("Removing node ", self, ", Goodbye!")
|
||||||
|
|
||||||
class FramebufferNode(Node, CGPipelineTreeNode):
|
class FramebufferNode(Node, CGPipelineTreeNode):
|
||||||
'''A custom node'''
|
'''A custom node'''
|
||||||
|
@ -356,6 +373,7 @@ node_categories = [
|
||||||
NodeItem("DrawWorldNodeType"),
|
NodeItem("DrawWorldNodeType"),
|
||||||
NodeItem("TargetNodeType"),
|
NodeItem("TargetNodeType"),
|
||||||
NodeItem("ColorBufferNodeType"),
|
NodeItem("ColorBufferNodeType"),
|
||||||
|
NodeItem("DepthBufferNodeType"),
|
||||||
NodeItem("FramebufferNodeType"),
|
NodeItem("FramebufferNodeType"),
|
||||||
]),
|
]),
|
||||||
MyPassNodeCategory("PASSNODES", "Pass", items=[
|
MyPassNodeCategory("PASSNODES", "Pass", items=[
|
||||||
|
@ -457,7 +475,7 @@ def buildNodeTree(node_group, shader_references, asset_references):
|
||||||
with open(path + node_group_name + '.json', 'w') as f:
|
with open(path + node_group_name + '.json', 'w') as f:
|
||||||
f.write(output.to_JSON())
|
f.write(output.to_JSON())
|
||||||
|
|
||||||
def make_set_target(stage, node_group, node, target_index=1, color_buffer_index=-1):
|
def make_set_target(stage, node_group, node, target_index=1, color_buffer_index=-1, is_depth_attachment=False):
|
||||||
stage.command = 'set_target'
|
stage.command = 'set_target'
|
||||||
targetNode = findNodeByLink(node_group, node, node.inputs[target_index])
|
targetNode = findNodeByLink(node_group, node, node.inputs[target_index])
|
||||||
|
|
||||||
|
@ -466,12 +484,19 @@ def make_set_target(stage, node_group, node, target_index=1, color_buffer_index=
|
||||||
if color_buffer_index >= 0 and targetNode.inputs[3].default_value > 1: # MRT target, bind only specified target
|
if color_buffer_index >= 0 and targetNode.inputs[3].default_value > 1: # MRT target, bind only specified target
|
||||||
cb_postfix = str(color_buffer_index)
|
cb_postfix = str(color_buffer_index)
|
||||||
|
|
||||||
|
elif is_depth_attachment == True: # Bind texture depth
|
||||||
|
cb_postfix = 'D'
|
||||||
|
|
||||||
targetId = targetNode.inputs[0].default_value + cb_postfix
|
targetId = targetNode.inputs[0].default_value + cb_postfix
|
||||||
|
|
||||||
elif targetNode.bl_idname == 'ColorBufferNodeType':
|
elif targetNode.bl_idname == 'ColorBufferNodeType':
|
||||||
cb_index = targetNode.inputs[1].default_value
|
cb_index = targetNode.inputs[1].default_value
|
||||||
make_set_target(stage, node_group, targetNode, target_index=0, color_buffer_index=cb_index)
|
make_set_target(stage, node_group, targetNode, target_index=0, color_buffer_index=cb_index)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
elif targetNode.bl_idname == 'DepthBufferNodeType':
|
||||||
|
make_set_target(stage, node_group, targetNode, target_index=0, is_depth_attachment=True)
|
||||||
|
return
|
||||||
|
|
||||||
elif targetNode.bl_idname == 'NodeReroute':
|
elif targetNode.bl_idname == 'NodeReroute':
|
||||||
make_set_target(stage, node_group, targetNode, target_index=0, color_buffer_index=color_buffer_index)
|
make_set_target(stage, node_group, targetNode, target_index=0, color_buffer_index=color_buffer_index)
|
||||||
|
@ -495,7 +520,7 @@ def make_draw_geometry(stage, node_group, node):
|
||||||
stage.command = 'draw_geometry'
|
stage.command = 'draw_geometry'
|
||||||
stage.params.append(node.inputs[1].default_value) # Context
|
stage.params.append(node.inputs[1].default_value) # Context
|
||||||
|
|
||||||
def make_bind_target(stage, node_group, node, target_index=1, constant_index=2, color_buffer_index=-1):
|
def make_bind_target(stage, node_group, node, target_index=1, constant_index=2, color_buffer_index=-1, is_depth_attachment=False):
|
||||||
stage.command = 'bind_target'
|
stage.command = 'bind_target'
|
||||||
targetNode = findNodeByLink(node_group, node, node.inputs[target_index])
|
targetNode = findNodeByLink(node_group, node, node.inputs[target_index])
|
||||||
|
|
||||||
|
@ -505,12 +530,19 @@ def make_bind_target(stage, node_group, node, target_index=1, constant_index=2,
|
||||||
if targetNode.bl_idname == 'ColorBufferNodeType': # Make recursive
|
if targetNode.bl_idname == 'ColorBufferNodeType': # Make recursive
|
||||||
color_buffer_index = targetNode.inputs[1].default_value
|
color_buffer_index = targetNode.inputs[1].default_value
|
||||||
targetNode = findNodeByLink(node_group, targetNode, targetNode.inputs[0])
|
targetNode = findNodeByLink(node_group, targetNode, targetNode.inputs[0])
|
||||||
|
|
||||||
|
if targetNode.bl_idname == 'DepthBufferNodeType': # Make recursive
|
||||||
|
is_depth_attachment = True
|
||||||
|
targetNode = findNodeByLink(node_group, targetNode, targetNode.inputs[0])
|
||||||
|
|
||||||
if targetNode.bl_idname == 'TargetNodeType':
|
if targetNode.bl_idname == 'TargetNodeType':
|
||||||
cb_postfix = ''
|
cb_postfix = ''
|
||||||
if color_buffer_index >= 0 and targetNode.inputs[3].default_value > 1: # MRT target, bind only specified target
|
if color_buffer_index >= 0 and targetNode.inputs[3].default_value > 1: # MRT target, bind only specified target
|
||||||
cb_postfix = str(color_buffer_index)
|
cb_postfix = str(color_buffer_index)
|
||||||
|
|
||||||
|
elif is_depth_attachment == True: # Bind texture depth
|
||||||
|
cb_postfix = 'D'
|
||||||
|
|
||||||
targetId = targetNode.inputs[0].default_value + cb_postfix
|
targetId = targetNode.inputs[0].default_value + cb_postfix
|
||||||
|
|
||||||
stage.params.append(targetId)
|
stage.params.append(targetId)
|
||||||
|
|
|
@ -5,6 +5,7 @@ precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
// uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform vec2 dir;
|
uniform vec2 dir;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ precision highp float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
// uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D gbuffer1;
|
uniform sampler2D gbuffer1;
|
||||||
uniform sampler2D noise256;
|
uniform sampler2D noise256;
|
||||||
|
|
|
@ -7,6 +7,7 @@ precision mediump float;
|
||||||
#define PI 3.1415926535
|
#define PI 3.1415926535
|
||||||
#define TwoPI (2.0 * PI)
|
#define TwoPI (2.0 * PI)
|
||||||
|
|
||||||
|
uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D gbuffer1;
|
uniform sampler2D gbuffer1;
|
||||||
uniform sampler2D gbuffer2;
|
uniform sampler2D gbuffer2;
|
||||||
|
@ -385,9 +386,12 @@ vec3 LTC_Evaluate(vec3 N, vec3 V, vec3 P, mat3 Minv, vec3 points0, vec3 points1,
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||||
|
// float depth = 1.0 - g0.a;
|
||||||
|
// if (depth == 0.0) discard;
|
||||||
|
if (depth == 1.0) discard;
|
||||||
|
|
||||||
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, mask, depth
|
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, mask, depth
|
||||||
float depth = 1.0 - g0.a;
|
|
||||||
if (depth == 0.0) discard;
|
|
||||||
|
|
||||||
vec4 g1 = texture(gbuffer1, texCoord); // Base color.rgb, roughn/met
|
vec4 g1 = texture(gbuffer1, texCoord); // Base color.rgb, roughn/met
|
||||||
float ao = texture(ssaotex, texCoord).r;
|
float ao = texture(ssaotex, texCoord).r;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D gbuffer1;
|
uniform sampler2D gbuffer1;
|
||||||
|
|
||||||
|
@ -50,8 +51,10 @@ void main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float depth = 1.0 - texture(gbuffer0, texCoord).a;
|
// float depth = 1.0 - texture(gbuffer0, texCoord).a;
|
||||||
if (depth == 0.0) {
|
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||||
|
// if (depth == 0.0) {
|
||||||
|
if (depth == 1.0) {
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D gbuffer1;
|
uniform sampler2D gbuffer1;
|
||||||
uniform sampler2D snoise;
|
uniform sampler2D snoise;
|
||||||
|
@ -52,7 +53,8 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
|
||||||
float radius = aoSize * randomVec.y;
|
float radius = aoSize * randomVec.y;
|
||||||
kernelVec.xy = ((rotMat * kernelVec.xy) / currentDistance) * radius;
|
kernelVec.xy = ((rotMat * kernelVec.xy) / currentDistance) * radius;
|
||||||
vec2 coord = texCoord + kernelVec.xy;
|
vec2 coord = texCoord + kernelVec.xy;
|
||||||
float depth = 1.0 - texture(gbuffer0, coord).a;
|
// float depth = 1.0 - texture(gbuffer0, coord).a;
|
||||||
|
float depth = texture(gbufferD, coord).r * 2.0 - 1.0;
|
||||||
vec3 pos = getPos(depth, coord) - currentPos;
|
vec3 pos = getPos(depth, coord) - currentPos;
|
||||||
|
|
||||||
float angle = dot(pos, currentNormal);
|
float angle = dot(pos, currentNormal);
|
||||||
|
@ -64,8 +66,10 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float depth = 1.0 - texture(gbuffer0, texCoord).a;
|
// float depth = 1.0 - texture(gbuffer0, texCoord).a;
|
||||||
if (depth == 0.0) {
|
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||||
|
// if (depth == 0.0) {
|
||||||
|
if (depth == 1.0) {
|
||||||
gl_FragColor = vec4(1.0);
|
gl_FragColor = vec4(1.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D gbuffer1;
|
uniform sampler2D gbuffer1;
|
||||||
uniform sampler2D snoise;
|
uniform sampler2D snoise;
|
||||||
|
@ -42,7 +43,8 @@ vec4 doDO(vec3 point, vec3 noise, float radius, vec3 center_pos, float max_dista
|
||||||
vec2 textureOffset = reflect( point.xy, noise.xy ).xy * radius;
|
vec2 textureOffset = reflect( point.xy, noise.xy ).xy * radius;
|
||||||
vec2 sample_tex = texCoord + textureOffset;
|
vec2 sample_tex = texCoord + textureOffset;
|
||||||
|
|
||||||
float depth = 1.0 - texture(gbuffer0, sample_tex).a;
|
// float depth = 1.0 - texture(gbuffer0, sample_tex).a;
|
||||||
|
float depth = texture(gbufferD, sample_tex).r * 2.0 - 1.0;
|
||||||
vec3 sample_pos = getPos(depth, sample_tex);
|
vec3 sample_pos = getPos(depth, sample_tex);
|
||||||
|
|
||||||
vec3 center_to_sample = sample_pos - center_pos;
|
vec3 center_to_sample = sample_pos - center_pos;
|
||||||
|
@ -58,8 +60,10 @@ vec4 doDO(vec3 point, vec3 noise, float radius, vec3 center_pos, float max_dista
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float depth = 1.0 - texture(gbuffer0, texCoord).a;
|
// float depth = 1.0 - texture(gbuffer0, texCoord).a;
|
||||||
if (depth == 0.0) {
|
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||||
|
// if (depth == 0.0) {
|
||||||
|
if (depth == 1.0) {
|
||||||
gl_FragColor = vec4(1.0);
|
gl_FragColor = vec4(1.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
uniform sampler2D gbuffer0; // Normal, depth
|
uniform sampler2D gbufferD;
|
||||||
|
uniform sampler2D gbuffer0; // Normal
|
||||||
uniform sampler2D gbuffer1; // Color, roughness
|
uniform sampler2D gbuffer1; // Color, roughness
|
||||||
uniform mat4 P;
|
uniform mat4 P;
|
||||||
uniform mat4 tiV;
|
uniform mat4 tiV;
|
||||||
|
@ -45,7 +46,8 @@ vec3 getPos(float depth) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float getDeltaDepth(vec3 hitCoord) {
|
float getDeltaDepth(vec3 hitCoord) {
|
||||||
depth = 1.0 - texture(gbuffer0, getProjectedCoord(hitCoord).xy).a;
|
// depth = 1.0 - texture(gbuffer0, getProjectedCoord(hitCoord).xy).a;
|
||||||
|
depth = texture(gbufferD, getProjectedCoord(hitCoord).xy).r * 2.0 - 1.0;
|
||||||
vec3 viewPos = getPos(depth);
|
vec3 viewPos = getPos(depth);
|
||||||
return viewPos.z - hitCoord.z;
|
return viewPos.z - hitCoord.z;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,8 @@ void main() {
|
||||||
if (viewNormal.z <= 0.9) discard; // Only up facing surfaces for now
|
if (viewNormal.z <= 0.9) discard; // Only up facing surfaces for now
|
||||||
viewNormal = tiV * normalize(viewNormal);
|
viewNormal = tiV * normalize(viewNormal);
|
||||||
|
|
||||||
float d = 1.0 - g0.a;
|
// float d = 1.0 - g0.a;
|
||||||
|
float d = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||||
vec3 viewPos = getPos(d);
|
vec3 viewPos = getPos(d);
|
||||||
|
|
||||||
vec3 reflected = normalize(reflect((viewPos.xyz), normalize(viewNormal.xyz)));
|
vec3 reflected = normalize(reflect((viewPos.xyz), normalize(viewNormal.xyz)));
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
|
||||||
|
@ -74,8 +75,9 @@ vec4 SSSSBlur(float sssWidth) {
|
||||||
// if (SSSS_STREGTH_SOURCE == 0.0) discard;
|
// if (SSSS_STREGTH_SOURCE == 0.0) discard;
|
||||||
|
|
||||||
// Fetch linear depth of current pixel
|
// Fetch linear depth of current pixel
|
||||||
vec4 g0 = texture(gbuffer0, texCoord);
|
// vec4 g0 = texture(gbuffer0, texCoord);
|
||||||
float depth = 1.0 - g0.a;
|
// float depth = 1.0 - g0.a;
|
||||||
|
float depth = texture(gbufferD, texCoord) * 2.0 - 1.0;
|
||||||
const float znear = 0.1;
|
const float znear = 0.1;
|
||||||
const float zfar = 1000.0;
|
const float zfar = 1000.0;
|
||||||
const float projectionA = zfar / (zfar - znear);
|
const float projectionA = zfar / (zfar - znear);
|
||||||
|
|
|
@ -12,6 +12,7 @@ precision mediump float;
|
||||||
const float PI = 3.1415926535;
|
const float PI = 3.1415926535;
|
||||||
const float TwoPI = (2.0 * PI);
|
const float TwoPI = (2.0 * PI);
|
||||||
|
|
||||||
|
uniform sampler2D gbufferD;
|
||||||
uniform sampler2D gbuffer0;
|
uniform sampler2D gbuffer0;
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
uniform sampler2D senvmapRadiance;
|
uniform sampler2D senvmapRadiance;
|
||||||
|
@ -354,11 +355,13 @@ float godRays(vec2 uv) {
|
||||||
return light;
|
return light;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, mask, depth
|
// vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, mask
|
||||||
float gdepth = 1.0 - g0.a;
|
// float gdepth = 1.0 - g0.a;
|
||||||
|
float gdepth = texture(gbufferD, texCoord) * 2.0 - 1.0;
|
||||||
vec4 colorOriginal = texture(tex, texCoord);
|
vec4 colorOriginal = texture(tex, texCoord);
|
||||||
if (gdepth == 0.0) {
|
// if (gdepth == 0.0) {
|
||||||
|
if (gdepth == 1.0) {
|
||||||
gl_FragColor = colorOriginal;
|
gl_FragColor = colorOriginal;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue