Giter Club home page Giter Club logo

godotssrwater's People

Contributors

marcelb avatar niceandgoodonline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

godotssrwater's Issues

Proposal for screen limits fading

Hi, thank you very much for your work!
I'm using your ssr code in a project of mine and works quite well. I've got a proposal for a simple fading effect to reduce the abrupt interruption of the SSR near the screen limits. Here it comes:

vec3 get_ssr_color(vec3 surface_view_position, vec3 normal_view_space, vec3 view_view_space, mat4 proj_m, mat4 inv_proj_m)
{
	vec3 current_position_view_space = surface_view_position;
	vec3 view_direction_view_space = view_view_space * -1.0;
	vec3 reflect_vector_view_space = normalize(reflect(view_direction_view_space.xyz, normal_view_space.xyz));
	vec2 current_screen_position = vec2(0.0);
	
	vec3 resulting_color = vec3(0.0);
	for(float travel=0.0; resulting_color.x <= 0.0 && travel < ssr_max_travel; travel = travel + ssr_resolution)
	{
		current_position_view_space += reflect_vector_view_space * ssr_resolution;
		current_screen_position = get_uv_from_view_position(current_position_view_space, proj_m);

		float depth_texture_probe_raw = texture(DEPTH_TEXTURE, current_screen_position).x;
		//float corrected_depth = vertex.z + (proj_m[3][2] / (depth_texture_probe_raw + proj_m[2][2]));
		vec3 depth_texture_probe_view_position = get_view_position_from_uv(current_screen_position, depth_texture_probe_raw, inv_proj_m);
		
		float depth_diff = depth_texture_probe_view_position.z - current_position_view_space.z;
		
		// inspired by https://imanolfotia.com/blog/1
		vec2 centered_screen_coords = smoothstep(0.2, 0.6, abs(vec2(0.5, 0.5) - current_screen_position.xy));
    	float screen_edge_factor = clamp(1.0 - (centered_screen_coords.x + centered_screen_coords.y), 0.0, 1.0);
		vec3 resulting_color_0 = texture(SCREEN_TEXTURE, current_screen_position).rgb * screen_edge_factor;
		resulting_color = (depth_diff >= 0.0 && depth_diff < ssr_max_diff) ? resulting_color_0 : vec3(0.0);	
	}
	return resulting_color;
}

[...]

vec3 ssr_color = get_ssr_color(surface_view_position, NORMAL, VIEW, PROJECTION_MATRIX, INV_PROJECTION_MATRIX);
vec3 water_color = depth_color+ssr_mix_strength*ssr_color;

I hope it will be helpful. I'm also working on introducing some jittering linked to surface roughness, will update in case.

Thank you again

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.