[DooM III] : in lavorazione Shader per l'acqua (attenzione 56k)
here's a water renderer I've been working on:
vi riporto il comunicato e il codice, scusate se non traduco ma fra parole e codice io non ci capisco niente
It uses a mirrorRenderMap and a custom shader to blend it with the current render, so far the features are:
- viewangle dependent blending
looking down shows you the bottom and looking into horizon will reflect (mirror)
- normal map blending
two maps scroll at different speeds and get blended for an "animated" result
- specular highlights (optional, included as a separate material)
MirrorRenderMap has a TON of bugs.
Most annoying is the one that causes the texcoords to offset on X-axis, it seems to originate from the leveleditor. Adjusting the parameters at the surface inspectors sometimes fixes this.
Then you can't put anything under the water. Things get mirrored above the water (looks really stupid).
The engine likes to clip out the mirror alot, manytimes when the mirror is very much visible to the player. On one of my test levels I fixed this by making the surface larger, as if the mirror was clipped when player was not standing on it (even when the surface was underneath other surfaces).
There's a map "water01" that demonstrates the water shaders. The fog is created in the leveleditor. I looked into making a depth relative fog but turns out you can only access one z value from the fragment program, that's the current z (would have needed previous z to compare).
Inside the shader (water02.vfp) you can adjust the distortion size (it's marked with a comment) which seems to jump 10x from level to level. Sometimes 0.02 is apporiate and sometimes 0.2. There's also a line that temporarily fixes the offset bug (currently commented out).
I'm getting busy with my job towards the summer so I tought I release this for you guys to work on.
Last edited by maha_x on Mon Feb 20, 2006 4:00 pm; edited 1 time in total
i noticed this in your shader:
Code:
### fetch, R2 is currentRender, R1 is mirrorRenderBuffer
TEX R1, TC1, texture[1], 2D;
TEX R2, TC2, texture[0], 2D;
is it possible then to distort only the mirror image created by the mirrorRenderMap command?
as you may have noticed, using "_currentRender" also distorts objects in front of the water. crank up the distortion and you'll easily see the player's hands and weapon distort along their edges.
so far, i don't think anyone has solved this yet. even raven software didn't find a solution they were comfortable enough with.
but here's the catch: for my water, i don't care about distorting objects under the water. i have deep lake water in my map so nothing is really visible below the surface anyway.
i do care about distorting the reflected image.
so is there a way to send the buffered mirror image to a pixel shader, distort it and then render it to the screen?
i don't know how to write pixel shaders so i could use your help.
I'm sure raven would have got it working if they needed it...
anyhow, it should work like this (change this segment):
Code:
### convert pixel position to texcoord
MUL TC1, fragment.position, program.env[1];
### this fixes the occational offset bug temporarily
#ADD TC1.x, TC1.x, -0.145;
### distort by localnormal
ADD_SAT TC1, TC1, localNormal;
MOV TC2, TC1;
MUL TC2, TC2, program.env[0];
### fetch, R2 is currentRender, R1 is mirrorRenderBuffer
TEX R1, TC1, texture[1], 2D;
TEX R2, TC2, texture[0], 2D;
change to
Code:
### convert pixel position to texcoord
MUL TC1, fragment.position, program.env[1];
MOV TC2, TC1;
### this fixes the occational offset bug temporarily
#ADD TC1.x, TC1.x, -0.145;
### distort by localnormal
ADD_SAT TC1, TC1, localNormal;
MUL TC2, TC2, program.env[0];
### fetch, R2 is currentRender, R1 is mirrorRenderBuffer
TEX R1, TC1, texture[1], 2D;
TEX R2, TC2, texture[0], 2D;
this should bypass the distort for the currentRender (didn't test)