Shader 2.5- Liquid Ripples

 This week mostly involved figuring out reactive water ripples, which I have finally fixed with the help of a second tutorial to complement the first. The reason the Unreal tutorial did not work was a mixture of faulty collision, incorrect UV space and smaller errors in the Blueprint. I also started adding versatility to the shader, so the artist can control the colour of the liquid, size of the ripples etc.



Beginning play resets the render targets and creates dynamic material instances of the required materials. The DMIs weren't initially there, but I added them so a new instance wouldn't be created every time the ripples looped.



On every tick, a function is called to find the overlap information. This calculates the position, size and strength of the initial force applied to the water surface, which is then given to the set waves function to assign the values. The size of the initial force depends on the size ratio between the overlapping actor and the liquid mesh, but I may change this later as the ripples will change with the mesh scale. The framerate of the ripples is independant of the world framerate, so they will not change speed if framerate increases or decreases. This controls the frequency of the loop which switches the render targets.


The set waves function converts the overlap position to UV space, along with setting the input values as the values for the ripple brush material. 


This material uses these values to create a white value at the position calculated earlier. This initialises the ripples. I had to add 0.5 to the position value, as the ripples were appearing at the edges of the water, and a print string told me that the UV range was -0.5 to 0.5 instead of 0- 1. 



The ripple loop cycles through the render targets and constantly applies them to the texture samples in the height calculation material. This formula is based on a programming algorithm found on a website I was advised to read, which involves adding up the surrounding pixels' previous values, dividing by 2, and subtracting the target its 2 previous value to get the current value. The buffers/ render targets are then swapped. When the loop ends, the normals for that frame are then calculated and applied to the texture sample in the main material.


There are also hit events that apply ripples using the same logic as the overlapping actor. I made two of them as a backup, but I will probably get rid of one in the final shader.


The render targets are set as the texture samples above in the main material, which then combine with the normals and world offset already present. 

This shader relied heavily on my own understanding of the tutorials and my lecturer in order to debug, but I have learned a lot about blueprints because of it. I should be able to improve this shader before the final submission.

Comments

Popular Posts