diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-05-19 17:41:42 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-05-19 18:09:12 +0300 |
commit | f6ffe12ddb4426bec802d099c3538a9b31e72f8c (patch) | |
tree | b6b55f1aee38d138feacafb19e681c16159f9006 /source | |
parent | 4c5e9d7c0df00ea0409bcda0f47fcd25c7ec777c (diff) |
OpenGL: convert old texture2D calls in FX shaders
And one texture1D call.
Diffstat (limited to 'source')
5 files changed, 68 insertions, 76 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl b/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl index 9221e3def2c..c4e7cff2b0b 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl @@ -1,11 +1,10 @@ uniform sampler2D depthbuffer; in vec4 uvcoordsvar; -#define texture2D texture void main(void) { - float depth = texture2D(depthbuffer, uvcoordsvar.xy).r; + float depth = texture(depthbuffer, uvcoordsvar.xy).r; /* XRay background, discard */ if (depth >= 1.0) { diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl index b8feb8280b2..15d30e75969 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl @@ -29,7 +29,6 @@ in vec2 depth_uv3; in vec2 depth_uv4; out vec4 FragColor; -#define texture2D texture float calculate_far_coc(in float zdepth) { @@ -65,40 +64,40 @@ void first_pass() offset_row[2] = 3.0 * offset_row[0]; /* heavily blur the image */ - vec4 color = texture2D(colorbuffer, color_uv1); - color += texture2D(colorbuffer, color_uv1 + offset_row[1]); - color += texture2D(colorbuffer, color_uv2); - color += texture2D(colorbuffer, color_uv2 + offset_row[1]); + vec4 color = texture(colorbuffer, color_uv1); + color += texture(colorbuffer, color_uv1 + offset_row[1]); + color += texture(colorbuffer, color_uv2); + color += texture(colorbuffer, color_uv2 + offset_row[1]); color /= 4.0; - depth.r = texture2D(depthbuffer, depth_uv1).r; - depth.g = texture2D(depthbuffer, depth_uv2).r; - depth.b = texture2D(depthbuffer, depth_uv3).r; - depth.a = texture2D(depthbuffer, depth_uv4).r; + depth.r = texture(depthbuffer, depth_uv1).r; + depth.g = texture(depthbuffer, depth_uv2).r; + depth.b = texture(depthbuffer, depth_uv3).r; + depth.a = texture(depthbuffer, depth_uv4).r; zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth); coc = calculate_near_coc(zdepth); - depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[0]).r; - depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[0]).r; - depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[0]).r; - depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[0]).r; + depth.r = texture(depthbuffer, depth_uv1 + offset_row[0]).r; + depth.g = texture(depthbuffer, depth_uv2 + offset_row[0]).r; + depth.b = texture(depthbuffer, depth_uv3 + offset_row[0]).r; + depth.a = texture(depthbuffer, depth_uv4 + offset_row[0]).r; zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth); coc = max(calculate_near_coc(zdepth), coc); - depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[1]).r; - depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[1]).r; - depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[1]).r; - depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[1]).r; + depth.r = texture(depthbuffer, depth_uv1 + offset_row[1]).r; + depth.g = texture(depthbuffer, depth_uv2 + offset_row[1]).r; + depth.b = texture(depthbuffer, depth_uv3 + offset_row[1]).r; + depth.a = texture(depthbuffer, depth_uv4 + offset_row[1]).r; zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth); coc = max(calculate_near_coc(zdepth), coc); - depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[2]).r; - depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[2]).r; - depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[2]).r; - depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[2]).r; + depth.r = texture(depthbuffer, depth_uv1 + offset_row[2]).r; + depth.g = texture(depthbuffer, depth_uv2 + offset_row[2]).r; + depth.b = texture(depthbuffer, depth_uv3 + offset_row[2]).r; + depth.a = texture(depthbuffer, depth_uv4 + offset_row[2]).r; zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth); coc = max(calculate_near_coc(zdepth), coc); @@ -110,16 +109,16 @@ void first_pass() /* second pass, gaussian blur the downsampled image */ void second_pass() { - vec4 depth = vec4(texture2D(depthbuffer, uvcoordsvar.xy).r); + vec4 depth = vec4(texture(depthbuffer, uvcoordsvar.xy).r); /* clever sampling to sample 2 pixels at once. Of course it's not real gaussian sampling this way */ - vec4 color = texture2D(colorbuffer, uvcoordsvar.xy) * 0.3125; - color += texture2D(colorbuffer, uvcoordsvar.xy + invrendertargetdim) * 0.234375; - color += texture2D(colorbuffer, uvcoordsvar.xy + 2.5 * invrendertargetdim) * 0.09375; - color += texture2D(colorbuffer, uvcoordsvar.xy + 4.5 * invrendertargetdim) * 0.015625; - color += texture2D(colorbuffer, uvcoordsvar.xy - invrendertargetdim) * 0.234375; - color += texture2D(colorbuffer, uvcoordsvar.xy - 2.5 * invrendertargetdim) * 0.09375; - color += texture2D(colorbuffer, uvcoordsvar.xy - 4.5 * invrendertargetdim) * 0.015625; + vec4 color = texture(colorbuffer, uvcoordsvar.xy) * 0.3125; + color += texture(colorbuffer, uvcoordsvar.xy + invrendertargetdim) * 0.234375; + color += texture(colorbuffer, uvcoordsvar.xy + 2.5 * invrendertargetdim) * 0.09375; + color += texture(colorbuffer, uvcoordsvar.xy + 4.5 * invrendertargetdim) * 0.015625; + color += texture(colorbuffer, uvcoordsvar.xy - invrendertargetdim) * 0.234375; + color += texture(colorbuffer, uvcoordsvar.xy - 2.5 * invrendertargetdim) * 0.09375; + color += texture(colorbuffer, uvcoordsvar.xy - 4.5 * invrendertargetdim) * 0.015625; FragColor = color; } @@ -128,8 +127,8 @@ void second_pass() /* third pass, calculate the final coc from blurred and unblurred images */ void third_pass() { - vec4 color = texture2D(colorbuffer, uvcoordsvar.xy); - vec4 color_blurred = texture2D(blurredcolorbuffer, uvcoordsvar.xy); + vec4 color = texture(colorbuffer, uvcoordsvar.xy); + vec4 color_blurred = texture(blurredcolorbuffer, uvcoordsvar.xy); float coc = 2.0 * max(color_blurred.a, color.a); -color.a; FragColor = vec4(color.rgb, coc); } @@ -138,10 +137,10 @@ void third_pass() /* fourth pass, blur the final coc once to get rid of discontinuities */ void fourth_pass() { - vec4 color = texture2D(colorbuffer, uvcoordsvar.xz); - color += texture2D(colorbuffer, uvcoordsvar.yz); - color += texture2D(colorbuffer, uvcoordsvar.xw); - color += texture2D(colorbuffer, uvcoordsvar.yw); + vec4 color = texture(colorbuffer, uvcoordsvar.xz); + color += texture(colorbuffer, uvcoordsvar.yz); + color += texture(colorbuffer, uvcoordsvar.xw); + color += texture(colorbuffer, uvcoordsvar.yw); FragColor = color / 4.0; } @@ -152,10 +151,10 @@ vec4 small_sample_blur(in sampler2D colorbuffer, in vec2 uv, in vec4 color) vec4 result = weight * color; weight *= 4.0; - result += weight * texture2D(colorbuffer, uv + color_uv1.xy); - result += weight * texture2D(colorbuffer, uv - color_uv1.xy); - result += weight * texture2D(colorbuffer, uv + color_uv1.yx); - result += weight * texture2D(colorbuffer, uv - color_uv1.yx); + result += weight * texture(colorbuffer, uv + color_uv1.xy); + result += weight * texture(colorbuffer, uv - color_uv1.xy); + result += weight * texture(colorbuffer, uv + color_uv1.yx); + result += weight * texture(colorbuffer, uv - color_uv1.yx); return result; } @@ -165,11 +164,11 @@ vec4 small_sample_blur(in sampler2D colorbuffer, in vec2 uv, in vec4 color) void fifth_pass() { vec4 factors; - vec4 color_orig = texture2D(colorbuffer, uvcoordsvar.xy); - vec4 highblurred = texture2D(blurredcolorbuffer, uvcoordsvar.xy); - vec4 mediumblurred = texture2D(mblurredcolorbuffer, uvcoordsvar.xy); + vec4 color_orig = texture(colorbuffer, uvcoordsvar.xy); + vec4 highblurred = texture(blurredcolorbuffer, uvcoordsvar.xy); + vec4 mediumblurred = texture(mblurredcolorbuffer, uvcoordsvar.xy); vec4 smallblurred = small_sample_blur(colorbuffer, uvcoordsvar.xy, color_orig); - float depth = texture2D(depthbuffer, uvcoordsvar.xy).r; + float depth = texture(depthbuffer, uvcoordsvar.xy).r; float zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), vec4(depth)).r; float coc_far = clamp(calculate_far_coc(zdepth), 0.0, 1.0); diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl index 913a8619270..c41c1d0820b 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl @@ -37,9 +37,6 @@ layout(location = 0) out vec4 fragData0; layout(location = 1) out vec4 fragData1; layout(location = 2) out vec4 fragData2; -#define texture2D texture - - #define M_PI 3.1415926535897932384626433832795 /* calculate 4 samples at once */ @@ -62,15 +59,15 @@ void downsample_pass() float far_coc, near_coc; /* custom downsampling. We need to be careful to sample nearest here to avoid leaks */ - vec4 color1 = texture2D(colorbuffer, downsample1); - vec4 color2 = texture2D(colorbuffer, downsample2); - vec4 color3 = texture2D(colorbuffer, downsample3); - vec4 color4 = texture2D(colorbuffer, downsample4); + vec4 color1 = texture(colorbuffer, downsample1); + vec4 color2 = texture(colorbuffer, downsample2); + vec4 color3 = texture(colorbuffer, downsample3); + vec4 color4 = texture(colorbuffer, downsample4); - depth.r = texture2D(depthbuffer, downsample1).r; - depth.g = texture2D(depthbuffer, downsample2).r; - depth.b = texture2D(depthbuffer, downsample3).r; - depth.a = texture2D(depthbuffer, downsample4).r; + depth.r = texture(depthbuffer, downsample1).r; + depth.g = texture(depthbuffer, downsample2).r; + depth.b = texture(depthbuffer, downsample3).r; + depth.a = texture(depthbuffer, downsample4).r; zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth); coc = calculate_coc(zdepth); @@ -123,22 +120,22 @@ void accumulate_pass(void) { void final_pass(void) { vec4 finalcolor; float totalweight; - float depth = texture2D(depthbuffer, uvcoord).r; + float depth = texture(depthbuffer, uvcoord).r; vec4 zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), vec4(depth)); float coc_near = calculate_coc(zdepth).r; float coc_far = max(-coc_near, 0.0); coc_near = max(coc_near, 0.0); - vec4 farcolor = texture2D(farbuffer, uvcoord); + vec4 farcolor = texture(farbuffer, uvcoord); float farweight = farcolor.a; if (farweight > 0.0) farcolor /= farweight; - vec4 nearcolor = texture2D(nearbuffer, uvcoord); + vec4 nearcolor = texture(nearbuffer, uvcoord); - vec4 srccolor = texture2D(colorbuffer, uvcoord); + vec4 srccolor = texture(colorbuffer, uvcoord); - vec4 coc = texture2D(cocbuffer, uvcoord); + vec4 coc = texture(cocbuffer, uvcoord); float mixfac = smoothstep(1.0, MERGE_THRESHOLD, coc_far); finalcolor = mix(srccolor, farcolor, mixfac); diff --git a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl index d9e037e7047..4904010c841 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl @@ -14,8 +14,6 @@ uniform sampler2D depthbuffer; // coordinates on framebuffer in normalized (0.0-1.0) uv space in vec4 uvcoordsvar; out vec4 FragColor; -#define texture1D texture -#define texture2D texture /* ssao_params.x : pixel scale for the ssao radious */ /* ssao_params.y : factor for the ssao darkening */ @@ -38,7 +36,7 @@ vec3 calculate_view_space_normal(in vec3 viewposition) float calculate_ssao_factor(float depth) { /* take the normalized ray direction here */ - vec2 rotX = texture2D(jitter_tex, uvcoordsvar.xy * ssao_sample_params.yz).rg; + vec2 rotX = texture(jitter_tex, uvcoordsvar.xy * ssao_sample_params.yz).rg; vec2 rotY = vec2(-rotX.y, rotX.x); /* occlusion is zero in full depth */ @@ -62,7 +60,7 @@ float calculate_ssao_factor(float depth) int num_samples = int(ssao_sample_params.x); for (x = 0; x < num_samples; x++) { - vec2 dir_sample = texture1D(ssao_concentric_tex, (float(x) + 0.5) / ssao_sample_params.x).rg; + vec2 dir_sample = texture(ssao_concentric_tex, (float(x) + 0.5) / ssao_sample_params.x).rg; /* rotate with random direction to get jittered result */ vec2 dir_jittered = vec2(dot(dir_sample, rotX), dot(dir_sample, rotY)); @@ -72,7 +70,7 @@ float calculate_ssao_factor(float depth) if (uvcoords.x > 1.0 || uvcoords.x < 0.0 || uvcoords.y > 1.0 || uvcoords.y < 0.0) continue; - float depth_new = texture2D(depthbuffer, uvcoords).r; + float depth_new = texture(depthbuffer, uvcoords).r; if (depth_new != 1.0) { vec3 pos_new = get_view_space_from_depth(uvcoords, viewvecs[0].xyz, viewvecs[1].xyz, depth_new); vec3 dir = pos_new - position; @@ -92,8 +90,8 @@ float calculate_ssao_factor(float depth) void main() { - float depth = texture2D(depthbuffer, uvcoordsvar.xy).r; - vec4 scene_col = texture2D(colorbuffer, uvcoordsvar.xy); + float depth = texture(depthbuffer, uvcoordsvar.xy).r; + vec4 scene_col = texture(colorbuffer, uvcoordsvar.xy); vec3 final_color = mix(scene_col.rgb, ssao_color.rgb, calculate_ssao_factor(depth)); FragColor = vec4(final_color.rgb, scene_col.a); } diff --git a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl index d3e4532427b..78241a798a2 100644 --- a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl @@ -3,18 +3,17 @@ uniform sampler2D textureSource; in vec2 texCoord_interp; out vec4 fragColor; -#define texture2D texture void main() { vec4 color = vec4(0.0); - color += texture2D(textureSource, texCoord_interp.st + vec2(-3.0 * ScaleU.x, -3.0 * ScaleU.y)) * 0.015625; - color += texture2D(textureSource, texCoord_interp.st + vec2(-2.0 * ScaleU.x, -2.0 * ScaleU.y)) * 0.09375; - color += texture2D(textureSource, texCoord_interp.st + vec2(-1.0 * ScaleU.x, -1.0 * ScaleU.y)) * 0.234375; - color += texture2D(textureSource, texCoord_interp.st + vec2(0.0, 0.0)) * 0.3125; - color += texture2D(textureSource, texCoord_interp.st + vec2(1.0 * ScaleU.x, 1.0 * ScaleU.y)) * 0.234375; - color += texture2D(textureSource, texCoord_interp.st + vec2(2.0 * ScaleU.x, 2.0 * ScaleU.y)) * 0.09375; - color += texture2D(textureSource, texCoord_interp.st + vec2(3.0 * ScaleU.x, 3.0 * ScaleU.y)) * 0.015625; + color += texture(textureSource, texCoord_interp.st + vec2(-3.0 * ScaleU.x, -3.0 * ScaleU.y)) * 0.015625; + color += texture(textureSource, texCoord_interp.st + vec2(-2.0 * ScaleU.x, -2.0 * ScaleU.y)) * 0.09375; + color += texture(textureSource, texCoord_interp.st + vec2(-1.0 * ScaleU.x, -1.0 * ScaleU.y)) * 0.234375; + color += texture(textureSource, texCoord_interp.st + vec2(0.0, 0.0)) * 0.3125; + color += texture(textureSource, texCoord_interp.st + vec2(1.0 * ScaleU.x, 1.0 * ScaleU.y)) * 0.234375; + color += texture(textureSource, texCoord_interp.st + vec2(2.0 * ScaleU.x, 2.0 * ScaleU.y)) * 0.09375; + color += texture(textureSource, texCoord_interp.st + vec2(3.0 * ScaleU.x, 3.0 * ScaleU.y)) * 0.015625; fragColor = color; } |