Bindable depth.

This commit is contained in:
Lubos Lenco 2016-05-13 00:08:11 +02:00
parent 9431337efe
commit a589a76250
10 changed files with 79 additions and 22 deletions

View file

@ -130,6 +130,23 @@ class ColorBufferNode(Node, CGPipelineTreeNode):
def free(self):
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):
'''A custom node'''
@ -356,6 +373,7 @@ node_categories = [
NodeItem("DrawWorldNodeType"),
NodeItem("TargetNodeType"),
NodeItem("ColorBufferNodeType"),
NodeItem("DepthBufferNodeType"),
NodeItem("FramebufferNodeType"),
]),
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:
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'
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
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
elif targetNode.bl_idname == 'ColorBufferNodeType':
cb_index = targetNode.inputs[1].default_value
make_set_target(stage, node_group, targetNode, target_index=0, color_buffer_index=cb_index)
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':
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.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'
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
color_buffer_index = targetNode.inputs[1].default_value
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':
cb_postfix = ''
if color_buffer_index >= 0 and targetNode.inputs[3].default_value > 1: # MRT target, bind only specified target
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
stage.params.append(targetId)

View file

@ -5,6 +5,7 @@ precision mediump float;
#endif
uniform sampler2D tex;
// uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform vec2 dir;

View file

@ -5,6 +5,7 @@ precision highp float;
#endif
uniform sampler2D tex;
// uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform sampler2D noise256;

View file

@ -7,6 +7,7 @@ precision mediump float;
#define PI 3.1415926535
#define TwoPI (2.0 * PI)
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform sampler2D gbuffer2;
@ -385,9 +386,12 @@ vec3 LTC_Evaluate(vec3 N, vec3 V, vec3 P, mat3 Minv, vec3 points0, vec3 points1,
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
float depth = 1.0 - g0.a;
if (depth == 0.0) discard;
vec4 g1 = texture(gbuffer1, texCoord); // Base color.rgb, roughn/met
float ao = texture(ssaotex, texCoord).r;

View file

@ -6,6 +6,7 @@
precision mediump float;
#endif
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
@ -50,8 +51,10 @@ void main() {
return;
}
float depth = 1.0 - texture(gbuffer0, texCoord).a;
if (depth == 0.0) {
// float depth = 1.0 - texture(gbuffer0, texCoord).a;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
// if (depth == 0.0) {
if (depth == 1.0) {
gl_FragColor = color;
return;
}

View file

@ -17,6 +17,7 @@
precision mediump float;
#endif
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform sampler2D snoise;
@ -52,7 +53,8 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
float radius = aoSize * randomVec.y;
kernelVec.xy = ((rotMat * kernelVec.xy) / currentDistance) * radius;
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;
float angle = dot(pos, currentNormal);
@ -64,8 +66,10 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
}
void main() {
float depth = 1.0 - texture(gbuffer0, texCoord).a;
if (depth == 0.0) {
// float depth = 1.0 - texture(gbuffer0, texCoord).a;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
// if (depth == 0.0) {
if (depth == 1.0) {
gl_FragColor = vec4(1.0);
return;
}

View file

@ -6,6 +6,7 @@
precision mediump float;
#endif
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
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 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 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() {
float depth = 1.0 - texture(gbuffer0, texCoord).a;
if (depth == 0.0) {
// float depth = 1.0 - texture(gbuffer0, texCoord).a;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
// if (depth == 0.0) {
if (depth == 1.0) {
gl_FragColor = vec4(1.0);
return;
}

View file

@ -5,7 +5,8 @@ precision mediump float;
#endif
uniform sampler2D tex;
uniform sampler2D gbuffer0; // Normal, depth
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0; // Normal
uniform sampler2D gbuffer1; // Color, roughness
uniform mat4 P;
uniform mat4 tiV;
@ -45,7 +46,8 @@ vec3 getPos(float depth) {
}
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);
return viewPos.z - hitCoord.z;
}
@ -189,7 +191,8 @@ void main() {
if (viewNormal.z <= 0.9) discard; // Only up facing surfaces for now
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 reflected = normalize(reflect((viewPos.xyz), normalize(viewNormal.xyz)));

View file

@ -41,6 +41,7 @@
precision mediump float;
#endif
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D tex;
@ -74,8 +75,9 @@ vec4 SSSSBlur(float sssWidth) {
// if (SSSS_STREGTH_SOURCE == 0.0) discard;
// Fetch linear depth of current pixel
vec4 g0 = texture(gbuffer0, texCoord);
float depth = 1.0 - g0.a;
// vec4 g0 = texture(gbuffer0, texCoord);
// float depth = 1.0 - g0.a;
float depth = texture(gbufferD, texCoord) * 2.0 - 1.0;
const float znear = 0.1;
const float zfar = 1000.0;
const float projectionA = zfar / (zfar - znear);

View file

@ -12,6 +12,7 @@ precision mediump float;
const float PI = 3.1415926535;
const float TwoPI = (2.0 * PI);
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D tex;
uniform sampler2D senvmapRadiance;
@ -354,11 +355,13 @@ float godRays(vec2 uv) {
return light;
}
void main() {
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, mask, depth
float gdepth = 1.0 - g0.a;
void main() {
// vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, mask
// float gdepth = 1.0 - g0.a;
float gdepth = texture(gbufferD, texCoord) * 2.0 - 1.0;
vec4 colorOriginal = texture(tex, texCoord);
if (gdepth == 0.0) {
// if (gdepth == 0.0) {
if (gdepth == 1.0) {
gl_FragColor = colorOriginal;
return;
}