havenphillip Posted October 22, 2019 Share Posted October 22, 2019 Is there a way to get rid of this doubling up of the gun and hands in the refraction shader? I'm wracking my brain here. Here's my fragment shader: #version 400 #define BFN_ENABLED 1 //Uniforms uniform sampler2D texture0;//diffuse map uniform sampler2D texture1;//light map uniform sampler2D texture2;//specular map uniform samplerCube texture5;//cube map uniform sampler2DMS texture9; uniform sampler2D texture10;//screen color uniform samplerCube texture15;//BFN map uniform vec4 materialcolorspecular; //uniform vec4 lighting_ambient; //uniform vec4 ambientlight; uniform int decalmode; uniform float materialroughness; uniform vec2 buffersize; uniform bool isbackbuffer; //Camera uniforms uniform mat4 cameramatrix; uniform mat4 projectioncameramatrix; uniform vec2 camerarange; uniform float camerazoom; uniform mat4 camerainversematrix; uniform mat3 cameranormalmatrix; uniform vec3 cameraposition; //My uniforms #define BUMPINESS 0.01 //Inputs in vec2 ex_texcoords0; in vec4 ex_color; in float ex_selectionstate; in vec3 ex_VertexCameraPosition; in vec4 ex_vertexposition; in vec3 ex_normal; in vec3 ex_tangent; in vec3 ex_binormal; in float clipdistance0; out vec4 fragData0; out vec4 fragData1; out vec4 fragData2; out vec4 fragData3; float DepthToZPosition(in float depth) { return camerarange.x / (camerarange.y - depth * (camerarange.y - camerarange.x)) * camerarange.y; } void main(void) { //Clip plane discard if (clipdistance0>0.0) discard; vec4 outcolor = ex_color; vec4 color_specular = materialcolorspecular; //Normal map vec3 normal = ex_normal; normal = texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0; float ao = normal.z; normal = ex_tangent*normal.x + ex_binormal*normal.y + ex_normal*normal.z; normal=normalize(normal); //Refraction //----------------------------------------------------------------- vec2 texcoord = (gl_FragCoord.xy / buffersize); if (isbackbuffer) texcoord.y = 1.0f - texcoord.y; vec3 texAdjust = vec3(texcoord.x,texcoord.y,1.0); //vec3 texAdjust = (vec3(texcoord.x*1.2,texcoord.y,1.5)+0.2 //+vec3(texcoord.x,texcoord.y+0.1,1.2) //+vec3(texcoord.x,texcoord.y/2.0,1.2)+0.5); texAdjust = normalize(texAdjust); vec4 screencolor = textureProj(texture10,texAdjust + normal.xyz*BUMPINESS); outcolor = screencolor * 0.75; //----------------------------------------------------------------- fragData0 = outcolor; #if BFN_ENABLED==1 //Best-fit normals fragData1 = texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z))); fragData1.a = fragData0.a; #else //Low-res normals fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a); #endif float specular = color_specular.r * 0.299 + color_specular.g * 0.587 + color_specular.b * 0.114; int materialflags=1; if (ex_selectionstate>0.0) materialflags += 2; if (decalmode==1) materialflags += 4;//brush if (decalmode==2) materialflags += 8;//model if (decalmode==4) materialflags += 16;//terrain if (materialroughness>=0.5) { materialflags += 32; if (materialroughness>=0.75) materialflags += 64; } else { if (materialroughness>=0.25) materialflags += 64; } fragData1.a = materialflags/255.0; fragData2 = vec4(0.0,0.0,0.0,specular); fragData3 = vec4(ex_VertexCameraPosition,1.0f); } Quote Link to comment Share on other sites More sharing options...
Josh Posted October 24, 2019 Share Posted October 24, 2019 The refraction shader should be reading the depth and only blending with pixels that fall below the transparent surface's depth value, not pixels that fall in front. Coincidentally, I am about to start on a global refraction effect in the new Vulkan renderer. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.