SHADER Question (Solved)

  • #1, von joemidSonntag, 06. März 2016, 03:28 Uhr vor 9 Jahren
    Saw this on Shadertoy. Any help as to how to implement into the Shader Toolkit?

    uniform sampler2D texture;
    uniform vec2 resolution;
    uniform vec3 overlayColor;
    
    void main()
    {
    vec2 uv = gl_FragCoord.xy / resolution.xy;
    
    if (uv.y > 0.3)// is air - no reflection or effect
    {
        gl_FragColor = texture2D(texture, vec2(uv.x, uv.y));
    }
    else
    {
        // Compute the mirror effect.
        vec4 color = texture2D(texture, vec2(uv.x, 0.6 - uv.y))
        vec4 finalColor = vec4(mix(color.rgb, overlayColor, 0.25), 1.0);
        gl_FragColor = finalColor;
    }
    }
    


    Thanks!

    Neuling

    87 Posts


  • #2, von joemidSonntag, 06. März 2016, 03:29 Uhr vor 9 Jahren
    Oh, sorry. This is a water reflection. Here is an example link...

    https://www.shadertoy.com/view/Xll3R7

    Neuling

    87 Posts

  • #3, von unrealSonntag, 06. März 2016, 16:26 Uhr vor 9 Jahren
    Sorry, I'm not answering your question but there is a similar shader FX made by SimonS. I made a downloadable demo project for the visionaire community (or just look at the youtube video), hope this help. See the link :

    Neuling

    66 Posts

  • #4, von afrlmeSonntag, 06. März 2016, 17:00 Uhr vor 9 Jahren
    Sorry, I'm not answering your question but there is a similar shader FX made by SimonS. I made a downloadable demo project for the visionaire community (or just look at the youtube video), hope this help. See the link :


    Well he can create the ripple effect using the shader toolkit. There are 4 ripple effects available that you could apply to a scene object. Make sure you add the water image into a scene object. The reflection though you might have to do by adding the reflections directly into the water image itself, either as a static image or as an animation, if the scene changes at all.

    I believe it is possible to create custom shader scripts too, as Simon provided an example of one ages back after he first implemented the shader stuff into the engine. I don't think it's as simple as copy / pasting an existing shader script into it though. You may have to rewrite certain things in the script to get it to work.

    Foren Imperator

    7285 Posts

  • #5, von joemidSonntag, 06. März 2016, 21:02 Uhr vor 9 Jahren
    Thanks Unreal. I am familiar with your demo- love it, BTW!

    Thanks Lee- yeah, I started using Simon's ripple shaders as a placeholder applied to objects.

    As there is no pre-made reflect shader, I had been planning to add a transparent animation for the reflection made in Sqirlz Morph, plus a mirrored character, adjusted, following the current character with a loop.

    But, this became pretty graphically intensive, especially when I tried to add additional characters- I hit a wall and reversed.

    Mucking around in the shader script, however, led me to a link to Shadertoy and then the water reflection script.

    As a layman; reflection seems like a simple proposition for the Shader Toolkit, right? In the roughest sense we are just duplicating the image and flipping it on the y axis.

    Unfortunately, I haven't had any luck implementing it! That may have to do with me not knowing what I'm doing.grin

    Maybe this is impossible with the current vers of the toolkit?

    Thanks again, guys.

    Neuling

    87 Posts

  • #6, von joemidSonntag, 06. März 2016, 21:06 Uhr vor 9 Jahren
    I mean, am I crazy? I think it looks sooo good! With some parallax scroll? It could add such depth to a room.

    Neuling

    87 Posts

  • #7, von SimonSSonntag, 06. März 2016, 21:49 Uhr vor 9 Jahren
    There are some requirements for the shaders. If you don't understand C it might be hard to get through. Try this:
    shader_effects["reflect"] = {shader=basic_fsh..[[
    
    #define texture iChannel0
    vec3 overlayColor = vec3(.5,1,1);
    
    void main()
    {
    vec2 uv = texcoord.xy;
    	float sepoffset = 0.005*cos(iGlobalTime*3.0);
    	if (uv.y > 0.3 + sepoffset)// is air - no reflection or effect
    	    	gl_FragColor = texture2D(texture, vec2(uv.x, uv.y));
    	else
    	{
        	// Compute the mirror effect.
            float xoffset = 0.005*cos(iGlobalTime*3.0+200.0*uv.y);
            float yoffset = ((0.3 - uv.y)/0.3) * 0.05*(1.0+cos(iGlobalTime*3.0+50.0*uv.y));
        	vec4 color = texture2D(texture, vec2(uv.x+xoffset , (0.6 - uv.y+ yoffset)));
        	// 
        	vec4 finalColor = vec4(mix(color.rgb, overlayColor, 0.25), 1.0);
        	gl_FragColor = color;
    	}
    }
    ]]}
    
    shaderAddEffect("reflect")
    

    Thread König

    1582 Posts

  • #8, von joemidMontag, 07. März 2016, 20:53 Uhr vor 9 Jahren
    Thanks, Simon! That is perfect!

    Neuling

    87 Posts

  • #9, von afrlmeMontag, 07. März 2016, 22:39 Uhr vor 9 Jahren
    That actually looks pretty funky. wink

    Foren Imperator

    7285 Posts