Play with Martinsh shaders

Hello!

In this post I try to play with Martins Upitis (Martinsh) shaders or just update his shaders.

I’m not experimented in GLSL so if you’ve any suggestion, you’re welcome!

Good night/day!

And thanks very much to Martinsh for its great work!

EDIT:

  • Simplified water:

Youtube tutorial https://www.youtube.com/watch?v=2MJYB-hCyiE

.blend http://www.mediafire.com/download/0zw5aqao4lamem5/waterSimplified.blend

Youtube tutorial part2 http://youtu.be/ONDhWjA3fBc

.blend http://www.mediafire.com/download/wila5917m3hmfv1/waterSimplified3.blend
.blend http://www.mediafire.com/download/ruxmsi5x22wgwdi/waterSimplified4.blend

At the end of the part2, you can multiply refraction by vec3(0.2, 0.4, 0.9) (red = 0.2, green = 0.4, blue = 0.9) for example if you want to change water color. resettimer and randomtime properties are not needed so you can remove the properties and the related code in watertexture.py script.

  • Parallax Martinsh shader UpToDate (hopping I made no mistake):

parallax_silhouette.blend (679 KB)

  • Reflections on a plane:

http://www.mediafire.com/download/250vebqzkgsj67p/reflectionsOnPlane.blend

  • Fire:

http://www.mediafire.com/download/aic4cz07qbl7clc/fire.blend

(in the materials tab, ZTransparency to 0 and face orientation to billboard)

Sub Surface Scattering:

Attachments

SSS.blend (1.71 MB)

Tasty waffles.

Nice work!

Video is set to private :smiley:

Sorry, fixed.

Thanks BPR!

@3d solar system builder: I did not understand what you mean? It’s just a little tuto about how make water sufaces with a plane with Martinsh watersurface.py script…

Anyway, thanks for feedbacks!

Hello!

Today I played with Martinsh reflections shader (adapted by Matin.hedin I think):

http://www.mediafire.com/download/250vebqzkgsj67p/reflectionsOnPlane.blend

I could have applied this technique for rendering reflections in the first file I shared but I made another scene.

All what you need to re_use this file is:

  • A plane with the 2 scripts attached (one sensor always in pulse mode and the other not) and 2 game properties
  • A sun
  • 2 cameras (take care about the names) (1 for the viewer and one for rendering the reflections)
  • A skydome to produce reflections on the plane
  • An empty UV grid texture on the first slot to receive image rendered by the second cam and computed with the shader
  • 3 other textures (in order) diffuse, normal, spec map.

I made few modifications in the scripts (correct some errors I had in the fragment shader and in the other script, and add 2 uniform as game properties to set reflectivity and bump)

The skyDome is from CT101 (Blendswap)
The plane texture from cgtextures
The 2 main scripts are from Martins Upitis adapted by Martin.hedin (I think… Sorry if I make a mistake)
The mouseLook.py script is from riyuzakisan

Thanks to them!

If someone demands, I can make a quick video tutorial on how to set the scene…

nothing to do with above:

Martinsh parallax shader up to date:

parallax_silhouette.blend (679 KB)

I hope I made no mistake…

Have a good day!

Is there a way increase the opacity of the water? I want water that is completely opaque.

Hello! You can watch the video tutorial I made. Otherwise, in the .blend I shared, you replace line 267:

gl_FragColor = vec4(vec3(color+(specColor*specular)),0.5);

by:

gl_FragColor = vec4(vec3(color+(specColor*specular)),1.0);

and you remove line 279:

mesh.materials[0].setBlending(bge.logic.BL_SRC_ALPHA, bge.logic.BL_ONE_MINUS_SRC_ALPHA)

Thanks, I had a look through and tried to change the water color as well but it had no effect. Any idea why?

Another thing was that it turned my character blue, any idea why?




I don’t know why your character becomes blue… You can post your issue in the Blender game engine support section with a .blend… Someone could help you…

About the water color, you have to change the reflection and refraction textures (reflection > a color such as your sky color. Refraction: whatever you want. Make some tests :slight_smile: To make your tests, you can do what I do in the tutorial: check your texture is not packed > UV image editor > new image >8x8 pixels > paint > T >tools and you choose colors >you change the texture in the texture tab. Once the color please you, you have to save the image on your hard drive and pack it into the .blend file.

Thanks, I will make good use of this.

Hello youle,

thank you for the tutorial: it’s a long time that i was trying to adapt that shader to some of my scenes without success, with your help i’m making the first good steps

since Martin’s shaders is a very useful resource, but it’s undocumented and quite complex, it would be great if someone who understands the way it works could make a more complete tutorial, including how to setup refraction end “real” reflection, that’s not present in your video

it would be a great service to the Blender Community

Thank you anyway, take care

Hello! I’ll try to make the part 2 of the tutorial (even if I don’t understand 1/1000 of Martinsh work) in the next days (or tonight… :slight_smile: )

EDIT: http://youtu.be/ONDhWjA3fBc

At the end of the part2, you can multiply refraction by vec3(0.2, 0.4, 0.9)(instead of 0.8) (red = 0.2, green = 0.4, blue, 0.9) for example if you want to change water color.

Thank you for the second part of the tutorial, finally i can get results from this excellent but very complex setup…

I was able to obtain reflections, but looks like i lost the specularity in the water:


I think the two textures “reflection” and “refraction” added at the beginning of part1 are not used anymore

Is there a way to tweak the other colors in the shader? I could modify the script so that the color value are read from the specular and diffuse color value of the shader (easier to use)

Bye

I don’t know… I made this second part very quickly. Now I realize that “randomtime” and “resettimer” properties are not used in the watertexture.py script so you can remove it (properties and related code in the script). To simplify color management, you can set uniforms in watersurface.py:

First you have to declare uniforms variables at the beginning of the fragment shader> uniform float red;
uniform float green;
uniform float blue;

then change> refraction*vec3(red, green, blue)

at the end of the script:

own[“shader”].setUniform1f(‘red’, own[“red”])
own[“shader”].setUniform1f(‘green’, own[“green”])
own[“shader”].setUniform1f(‘blue’, own[“blue”])

and add float red, green, blue properties to the water.

Then you can adjust properties value to change water color.

The reflection and refraction textures used at the beginning of the tuto are not used anymore… Replaced with real time captures by watercamera.

For the specular reflection, could you share a .blend?

For the specular color, I’ll see if I find a good way to change it…

You need to know that this setup of the water is incomplete. Martinsh use other scripts to render water. Particularely groundwater.py

EDIT: To modify specular color, you can use the same system:

line 267: gl_FragColor = vec4(vec3(color+(specColorspecularvec3(0.1, 0.9, 0.1))),0.5);

> green specular

(specular depends on sun position)

EDIT2: Another option to get the diffuse color of your material is:

vec4 color = gl_FrontMaterial.emission; //Paradoxal but gl_FrontMaterial.diffuse is not supported
(vec3 rgbColor = color.rgb; )

(you have to increase the emit value of your material)