Jump to content

4.4 beta water physics and shader issues


Recommended Posts

Looks like some shaders are very buggy now, when I try to use shadmar's 08_pp_bloom.lua shader I get this result:

UmIYgAd.jpg

The native SSR shader is also not working anymore

Video 0:36 timestamp - The physcs on water are pretty funny now too (I undestand that its not finished yet)
Water physics plays a big part on my game.

 

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

Replace the fragment program of the SSR shader with this:
 

//---------------------------------------------------------------------------
// Screen-Space Reflection shader by Igor Katrich, Shadmar, and Josh
//---------------------------------------------------------------------------
#version 400

uniform sampler2DMS texture0;
uniform sampler2D texture1;
uniform sampler2DMS texture2;
uniform sampler2DMS texture3;
uniform sampler2DMS texture4;

uniform bool isbackbuffer;
uniform vec2 buffersize;

uniform mat4 projectioncameramatrix;
uniform vec3 cameraposition;
uniform mat3 cameranormalmatrix;
uniform mat3 camerainversenormalmatrix;

//User variables
#define reflectionfalloff 10.0f
#define raylength 1.1f
#define maxstep 10
#define edgefadefactor 0.95f
#define hitThreshold 0.1

out vec4 fragData0;

vec4 getPosition(in vec2 texCoord, out float z)
{
        float x = texCoord.s * 2.0f - 1.0f;
        float y = texCoord.t * 2.0f - 1.0f;
        z = texelFetch(texture0, ivec2(texCoord*buffersize),0).r;
        vec4 posProj = vec4(x,y,z,1.0f);
        vec4 posView = inverse(projectioncameramatrix) * posProj;
        posView /= posView.w;
        return posView;
		
		/*
		//VR Sheared mprojection
		vec4 screencoord = texelFetch(texture4,ivec2(texCoord*buffersize),0);
		screencoord.y *= -1.0f;
		return screencoord;*/
}

float LinePointDistance(in vec3 v, in vec3 w, in vec3 p)
{
  // Return minimum distance between line segment vw and point p
        vec3 d = w-v;
        float l2 = d.x*d.x+d.y*d.y+d.z*d.z;  // i.e. |w-v|^2 -  avoid a sqrt
        if (l2 == 0.0) return distance(p, v);   // v == w case
        //float t = max(0.0f, min(1.0f, dot(p - v, w - v) / l2));
        float t = dot(p - v, w - v) / l2;
        vec3 projection = v + t * (w - v);  // Projection falls on the segment
        return distance(p, projection);
}

void main(void)
{
        vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
        if (isbackbuffer) icoord.y = 1.0f - icoord.y;
        
        //Get screen color
        vec4 color = texture(texture1,icoord);

        //Get normal + alpha channel.
        vec4 n=texelFetch(texture2, ivec2(icoord*buffersize),0);
        vec3 normalView = normalize(n.xyz * 2.0f - 1.0f);
        
        //Get roughness from gbuffer (normal.a)
        int materialflags = int(n.a*255.0+0.5);
        int roughness=1;
        //if ((32 & materialflags)!=0) roughness += 4;
        //if ((64 & materialflags)!=0) roughness += 2;
        
        //Get specmap from gbuffer
        float specularity = texelFetch(texture3, ivec2(icoord*buffersize),0).a;
        
        //only compute if we hvae specularity
        if (specularity > 0.0f)
        {
                //Get position and out depth (z)
                float z;
                vec3 posView = getPosition(icoord,z).xyz;
                
                //Reflect vector
                vec4 reflectedColor = color;
                vec3 reflected = normalize(reflect(normalize(posView-cameraposition), normalView));
                
                float rayLength = raylength;
                vec4 T = vec4(0.0f);
                vec3 newPos;
                
                //Raytrace
                for (int i = 0; i < maxstep; i++)
                {       
                        newPos = posView + reflected * rayLength;
                        
                        T = projectioncameramatrix * vec4(newPos, 1.0f);
                        T.xy = vec2(0.5f) + 0.5f * T.xy / T.w;
                        T.z /= T.w;
                        
                        if (abs(z - T.z) < 1.0f && T.x <= 1.0f && T.x >= 0.0f && T.y <= 1.0f && T.y >= 0.0f)
                        {
                                float depth;
                                newPos = getPosition(T.xy,depth).xyz;
                                rayLength = length(posView - newPos);
                                
                                //Check distance of this pixel to the reflection ray.  If it's close enough we count it as a hit.
                                if (LinePointDistance(posView,posView+reflected,newPos) < hitThreshold)
                                {
                                        //Get the pixel at this normal
                                        vec4 n1=texelFetch(texture2, ivec2(T.xy*buffersize),0);
                                        vec3 normalView1 = normalize(n1.xyz * 2.0f - 1.0f);
                                        
                                        //Make sure the pixel faces the reflection vector
                                        if (dot(reflected,normalView1)<0.0f)
                                        {
                                                /*float m = max(1.0f-T.y,0.0f);
                                                          m = max(1.0f-T.x,m);
                                                          m += roughness * 0.1f;
                                                        */      
                                                float m = 0.5;
                                                vec4 rcol=texture(texture1,T.xy);
                                                reflectedColor = mix(rcol,color,clamp(m,0.0f,1.0f));
                                                //reflectedColor = rcol + color;
												//reflectedColor = max(rcol, color);

                                                //Fading to screen edges
                                                vec2 fadeToScreenEdge = vec2(1.0f);
                                                
                                                float edgedistance[2];
                                                edgedistance[1] = 0.20;
                                                edgedistance[0] = edgedistance[1] * (buffersize.y / buffersize.x);

                                                if (T.x<edgedistance[0])
                                                {
                                                        fadeToScreenEdge.x = T.x / edgedistance[0];
                                                }
                                                else if (T.x > 1.0 - edgedistance[0])
                                                {
                                                        fadeToScreenEdge.x = 1.0 - ((T.x - (1.0 - edgedistance[0])) / edgedistance[0]);
                                                }
                                                if (T.y<edgedistance[1])
                                                {
                                                        fadeToScreenEdge.y = T.y / edgedistance[1];
                                                }
                                                else if (T.y>1.0-edgedistance[1])
                                                {
                                                        fadeToScreenEdge.y = 1.0 - (T.y - (1.0-edgedistance[1])) / edgedistance[1];
                                                }
                                                
                                                float fresnel =  reflectionfalloff * (1.0f-(pow(dot(normalize(posView-cameraposition), normalize(normalView)), 2.0f)));
                                                fresnel = clamp(fresnel,0.0f,1.0f);
                                                color = mix(color, reflectedColor,clamp(fresnel * fadeToScreenEdge.x * fadeToScreenEdge.y * specularity, 0.0f, 1.0f));
                                                
                                                //We hit the pixel, so we're done, right?
                                                break;
                                        }
                                }
                        }
                        else
                        {
                                break;//exit because we're out of the texture
                        }
                }               
        }
        fragData0 = color;
}

 

  • Upvote 1

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

I don't have shadmar's bloom shader.  Where can I download this?

There is something wrong with the water buoyancy, for sure.

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

13 minutes ago, Josh said:

I don't have shadmar's bloom shader.  Where can I download this?

There is something wrong with the water buoyancy, for sure.

Thank you for the fast response :D
I tried mess with the object mass but anything >0 make the buoyancy go crazy.

The SSR is working now thanks for your new fragment code.

You can download his shader pack here:
https://www.leadwerks.com/community/topic/15383-underwater-shader/#comment-103236

 

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

The reason for this is a change I made to the Blit command, for VR.  I will work this out so the default behavior stays the same as before.

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

  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...