flachdrache Posted September 23, 2011 Share Posted September 23, 2011 Hey, i made a small modification to the early released "river node" ... or the river.frag to be precise. You most likely want to build roads as usual, carve its river beds with it and replace the road material with the following. the material file : color=1,1,1,0.85 texture0="riverwater04_color.dds" // diffuse texture1="riverwater03_nm.dds" // normal texture2="tag::rendercolor" texture3="tag::renderdepth" texture4="river_UnderwaterCube.dds" // diffuse or ambient cubemap shader="abstract::mesh_diffuse_bumpmap.vert","abstract::river.frag" zsort=1 depthmask=0 bumpscale=50 cullface=0 the "river.frag" : #extension GL_ARB_draw_buffers : enable #define LW_DIFFUSE texture0 // added - colormap #define LW_CUBEMAP_DIFFUSE texture4 // added - cube surface map #define LW_BUMPMAP texture1 #define LE_REFRACTION texture2 #define LE_DEPTHBUFFER texture3 uniform vec3 cameraposition; uniform vec2 buffersize; uniform vec2 camerarange; include "abstract::greyscale.txt" include "abstract::DepthToZPosition.frag" // added #ifdef LW_DIFFUSE uniform sampler2D LW_DIFFUSE; #endif #ifdef LW_CUBEMAP_DIFFUSE uniform samplerCube LW_CUBEMAP_DIFFUSE; #endif // -- #ifdef LW_BUMPMAP uniform sampler2D LW_BUMPMAP; #endif #ifdef LE_REFRACTION uniform sampler2D LE_REFRACTION; uniform sampler2D LE_DEPTHBUFFER; uniform float refractionstrength = 0.01; #endif varying vec3 vertexposition; varying vec3 T,B,N; varying vec2 texcoord0; varying vec2 texcoord1; varying vec3 cubecoord; varying vec4 modelvertex; varying vec4 fragcolor; float fOcclusionShadow = 1.0; uniform sampler2D texture14; uniform float terrainsize; uniform vec3 terrainscale; uniform float bumpscale; uniform float specular; uniform float gloss; //Terrain color map uniform sampler2D texture12; uniform float apptime; void main(void) { vec4 diffuse = fragcolor; vec3 normal; float shininess = 0.0; vec2 texcoord=texcoord0;// only use this because of parallax mapping float selfillumination = 0.0; //mod texcoords for diffuse map - //rivernodes might cant deal with anglemod it seams ... texcoord.y += apptime / 20000.0; vec2 terraincoord; float terrainresolution; #ifdef LW_DIFFUSE // added diffuse *= texture2D(LW_DIFFUSE,texcoord); #endif #ifdef LW_CUBEMAP_DIFFUSE // added diffuse = vec4( pow(diffuse.xyz, 1.0-(textureCube(LW_CUBEMAP_DIFFUSE, cubecoord).xyz)), diffuse.w); #endif normal = N; #ifdef LW_BUMPMAP vec4 bumpcolor = texture2D(LW_BUMPMAP,texcoord); bumpcolor += texture2D(LW_BUMPMAP,vec2(texcoord.x+0.5,texcoord.y+apptime / 20000.0)); bumpcolor /= 2.0; normal = bumpcolor.xyz * 2.0 - 1.0; normal.z /= bumpscale; normal = T * normal.x + B * normal.y + N * normal.z; normal = normalize(normal); #endif #ifdef LE_REFRACTION diffuse.a=0.25; vec4 refractionvector = vec4( gl_FragCoord.x/buffersize.x, gl_FragCoord.y/buffersize.y, gl_FragCoord.z, 1.0 ); float backgrounddepth=texture2D(LE_DEPTHBUFFER,gl_FragCoord.xy/buffersize).x; backgrounddepth=DepthToZPosition(backgrounddepth); float foregrounddepth=DepthToZPosition(gl_FragCoord.z); float rmix = clamp((backgrounddepth-foregrounddepth)/1.0,0,1); vec4 refractionvector2 = refractionvector + refractionstrength * vec4(normal,0.0) * rmix; backgrounddepth=texture2DProj(LE_DEPTHBUFFER,refractionvector2).x; diffuse = diffuse * rmix + vec4(1) * (1.0-rmix); vec4 transparency; if (backgrounddepth>gl_FragCoord.z) { backgrounddepth=DepthToZPosition(backgrounddepth); transparency = texture2DProj(LE_REFRACTION,refractionvector2); if (rmix<1.0) { transparency = transparency * rmix + (1.0-rmix) * texture2DProj(LE_REFRACTION,refractionvector); } diffuse = transparency * diffuse; } else { diffuse = texture2DProj(LE_REFRACTION,refractionvector)*diffuse; } #endif vec3 adjustednormal = normal*0.5+0.5; float adjustedgloss = gloss; //Diffuse gl_FragData[0] = diffuse; gl_FragData[1] = vec4(adjustednormal,diffuse.w); gl_FragData[3] = vec4(0,0,0,diffuse.w); shininess=clamp(shininess,0,1)*0.5; gl_FragData[2]=vec4(shininess,gloss,0.0,diffuse.w); } note : texture2="tag::rendercolor" texture3="tag::renderdepth" do need to be present and unobstructed too. e.g. on surface, model construction : local world=CurrentWorld() SetWorld(fw.transparency.world) self.rivermesh=CreateMesh(nil) SetWorld(world) ... should all be self-explanatory - hf. Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
flachdrache Posted September 23, 2011 Author Share Posted September 23, 2011 Whoops, the mesh.vert need to have "cubecoord" defined of course and its content should look somwhat like this ... // ... texcoord0=gl_MultiTexCoord0.xy; texcoord1=gl_MultiTexCoord1.xy; //#ifdef LW_CUBEMAP cubecoord = modelvertex.xyz - cameraposition; cubecoord = reflect( cubecoord , normalize(nmat * gl_Normal.xyz) ); //#endif nmat = gl_NormalMatrix * nmat; // ... Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted February 24, 2012 Share Posted February 24, 2012 Nice!! This is exactly what I needed Could you put this as a downloadable file in the assets? Quote Link to comment Share on other sites More sharing options...
flachdrache Posted February 24, 2012 Author Share Posted February 24, 2012 tbh - thats not my work and i never had the files of the "river-nodes" from the showcase video ... which means, no projected caustics so far. Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted March 2, 2012 Share Posted March 2, 2012 Actually, I took a look at mesh.vert and it looks different than your modified version. Which to I use?? texcoord0=gl_MultiTexCoord0.xy; texcoord1=gl_MultiTexCoord1.xy; // -- (flachdrache's version with cube coordinates) -- //#ifdef LW_CUBEMAP cubecoord = modelvertex.xyz - cameraposition; cubecoord = reflect( cubecoord , normalize(nmat * gl_Normal.xyz) ); //#endif // -- //(Vanilla 2.5 install) #ifdef LW_CUBEMAP cubemapdir = normalize( modelvertex.xyz - cameraposition ); cubemapnormal = normalize(nmat * gl_Normal).xyz; //cubecoord = reflect( normalize( modelvertex.xyz - cameraposition ) , normalize(nmat * gl_Normal).xyz ); #endif nmat = gl_NormalMatrix * nmat; Quote Link to comment Share on other sites More sharing options...
flachdrache Posted March 2, 2012 Author Share Posted March 2, 2012 depends ... with my sheer knowledge of shader programming i would say that one "reflect" beats two instances of "normalize" in terms of speed + processing vertexshaders is basically allways faster as fragmentshader processing but since i dont know what the compiled shader expect to be better, i play it save and say - add the old "cubecoord" instance to your .vert/.frag ... just the "varying vec3 cubecoord;" in the mesh.frag though. PS: iam not aware of random changes to some 2.5 shader ( insert funny EvilSmiley here). Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.