Blood & Water Effects [Irrlicht 1.7.1]

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Blood & Water Effects [Irrlicht 1.7.1]

Post by Bate »

Blood & Water Effects
Image

As promised, I revived BlindSide's old water shader, so here it is. However, I made quite a few changes and since I barely speak GLSL it's DX only for now.
  • All terrain dependencies stripped, it's only the water surface but therefore universal
  • Implemented as a SceneNode with some parameters, it takes 1 line of code to create it
  • It's movable, scalable and works with parents
  • Should work with most custom cameras
  • Sinus waves and refraction are now switchable at runtime
  • Minor changes in color and transparency
  • It's extremely fast, even a little faster than before due to the cuts in terrain code (in the screenshot VSync is on, therefore capped at 75fps)
Note:
If shader materials are used on objects that intersect with the clip plane (the water surface) it's necessary to implement the clip plane inside those shaders as well in order to make reflections and refractions work correctly.

In HLSL a basic shader with a custom clip plane could look like this:

Code: Select all

float4x4 xWorldViewProjection;
float4x4 xWorld;

struct VertexToPixel
{
    float4 Position   : POSITION0;
    float2 TexCoords  : TEXCOORD0;
    float3 Position3D : TEXCOORD1;
};

struct PixelToFrame
{
    float4 Color      : COLOR0;
};

VertexToPixel vertexMain ( float4 inPos       : POSITION0,
                           float2 inTexCoords : TEXCOORD0 )
{
    VertexToPixel Output;

    Output.Position   = mul(inPos, xWorldViewProjection);
    Output.TexCoords  = inTexCoords;
    Output.Position3D = mul(inPos, xWorld);

    return Output;
}

// ================================================================

sampler2D diffuse : register(s0);
float seaLevel; // SceneNode Y position

PixelToFrame pixelMain(VertexToPixel PSIn)
{
    clip(PSIn.Position3D.y - seaLevel); // clip if below seaLevel

    PixelToFrame Output;

    float4 final = tex2D(diffuse, PSIn.TexCoords);

    Output.Color = final;

    return Output;
}
In addition, I included my new blood effect. It's not 'perfect' yet since there's a lot of tweaking and fine tuning involved. Anyway, feel free to improve and/or extend it to your liking.
  • Implemented as a SceneNode, it takes 1 line of code to create an effect
  • It's self-controlled, so actually all you need to do is call new Effect(...) just where you need it. It destroys itself on animation end, so there's no need to store a pointer.
  • particle-based
  • simple texture animation shader
Image

Demo controls:
Key [ESC] : Exit
Mouse [LEFT] : Shoot (aim for Mr. Ball)
Key [1] : Show blood effect - mild
Key [2] : Show blood effect - medium
Key [3] : Show blood effect - brutal
Key [4] : Show blood effect - insane
Key [5] : Show massacre :)


Download package here.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
d3jake
Posts: 198
Joined: Sat Mar 22, 2008 7:49 pm
Location: United States of America

Post by d3jake »

Cool! Whether it's you or someone else that gets to it, I'm looking forward to a GLSL version of this.
The Open Descent Foundation is always looking for programmers! http://www.odf-online.org
"I'll find out if what I deleted was vital here shortly..." -d3jake
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

I can do a glsl version later.
Edit : DONE!, see next post after the Virion one.
Last edited by stefbuet on Thu Aug 19, 2010 5:26 pm, edited 6 times in total.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

I think the water shader lack of something. Maybe stronger specular?

This are some of the water render I did in Blender recently (not real-time) but I realize with sharp/strong specular it looks more convincing.

Image

Image
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

Ok, here is the OpenGL (GLSL) version :

First, you forget to send texture adress in the shader callback, it worked with DX but fail with openGL :

add this lines to the OnSetConstants function in CWaterShader.cpp :

Code: Select all

int ReflectionTextureAdress=0, NormalMapAdress=1, DUDVMapAdress=2;
  services->setPixelShaderConstant ("ReflectionTexture", (float*)&ReflectionTextureAdress, 1);
  services->setPixelShaderConstant ("NormalMap", (float*)&NormalMapAdress, 1);
  services->setPixelShaderConstant ("DUDVMap", (float*)&DUDVMapAdress, 1);
Same with the blood effect :
In the OnSetConstants function in CBloodShader.cpp you can add this :

Code: Select all

int bloodAdress=0;
services->setPixelShaderConstant("blood", (float*)&bloodAdress, 1);
Now here are the GLSL shaders,
you just have to change the path to the new vertex/pixel shaders.
By the way, I included modified CPP files into the archive so you don't have to change anything to the code.

Here is the archive with shaders & cpp files:
http://www.easy-share.com/1911934210/openGL patch.rar

Don't forget to change your driver to be EDT_OPENGL :roll:
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post by wing64 »

Goodjob :D
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

great! :D
I am integrating to my game now :D
programmer is bad designer
designer is bad programmer
trivtn
Posts: 132
Joined: Tue Jan 17, 2006 12:30 pm
Location: Viet Nam
Contact:

Post by trivtn »

Cool ! Thanks !
There's something is fantastic, there's nothing is absolute.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Virion wrote:I think the water shader lack of something. Maybe stronger specular?
You can combine it with the water from my competition entry to get a similar effect.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

AWESOME EFFECT! reminds me of gears of war. Definitely one of the best I've seen. Ca you add like specular to the blood or something?
Image
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Yeah, I already thought about it. Some glossiness would probably help to create plasticity.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

thin blood is semi transparent, and refractive (like water) you need to add that. simple, just make a normal map adequate to your particles and watch the world displaced. An alpha value of 200 would work well as blood in not "red water" its a bit thicker. actually you could attenuate the alpha according to the thickness of the blob of blood, make like a relief map, normal plus heightmap combined. I will get you a picture if I can
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

that is what I meant

Image
jorgerosa
Competition winner
Posts: 117
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal
Contact:

Post by jorgerosa »

This is soooooooooooooo cool! The water effect that I have loved so much for so many time... is now available !!! (I´ve found this new thread by chance, maybe a link should be added in the old one, no?) THANKYOU SO MUCH to "Blindside" for share his original code, to "Bate" for doing his homework and share it, and to "stefbuet" for share his OpenGL (GLSL) version !!!

Its integration is really easy, even for a Irrlicht neewbie like me!
This is what I was trying to achieve at: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=39568
So, i think that i will loose the first prize (a brand new toaster). It´s all your fault!!!... Nvm, I´ll try to live without it, and I´ll try again next month. I´ve heard that the 1st prize will be an Ferrari Aurea... :wink:
BlindSide wrote:You can combine it with the water from my competition entry to get a similar effect.
WOW! I hope to live to see it! That would be just perfect!

Image

ISSUE: I´ve an issue, as you can see in the picture... Part of "nau" object is missing/not visible (Just some notes: It´s imported from an ".obj" file format, and I´m using OpenGL (GLSL) version here)
--> I´m I missing something in my code or is it a bug?... Or that happens in real life and I´ve been distracted?... Thanks in advance. :D


EDIT (9 sept 2010)
Image
I´ve found how to work around with the above issue.
I´ve edited "CWaterSurface.h" file, and edited this line "#define CLIP_PLANE_OFFSET 2.0f" to "#define CLIP_PLANE_OFFSET 200.0f"
Fixed the "nau" issue but creates an terrain reflexion error(?). Can someone help on this? Thankyou.
Last edited by jorgerosa on Wed Jan 11, 2012 6:11 am, edited 1 time in total.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

The CLIP_PLANE_OFFSET is meant to be used for slight adjustments only, which means it should be kept close to 0 (exactly 0 at best).

If you define it 200 the clipplane is moved 200 units along the Y axis which messes up the reflection shot (too much or too little (+/- value) of the terrain is visible by the reflection camera).
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply