As for bilinear filtering, here you go:
#define textureSize 256.0
#define texelSize 1.0 / 256.0
vec4 texture2D_bilinear( uniform sampler2D tex, vec2 uv )
{
vec2 f = fract( uv.xy * textureSize );
vec4 t00 = texture2D( tex, uv );
vec4 t10 = texture2D( tex, uv + vec2( texelSize, 0.0 ));
vec4 tA = mix( t00, t10, f.x );
vec4 t01 = texture2D( tex, uv + vec2( 0.0, texelSize ) );
vec4 t11 = texture2D( tex, uv + vec2( texelSize, texelSize ) );
vec4 tB = mix( t01, t11, f.x );
return mix( tA, tB, f.y );
}
Code taken from ozone3D.net
Why would I do this instead of a cheaper method?
Because:
-
The ocean shader seems to work pretty nicely, so the concept works. At higher details, it slows down considerably, but then again, there’s extra rendering involved. As for CGgap’s version, the maths might be taking a bit of calculi as well.
-
Depending on the size of the displacement maps, I can have highly detailed surfaces (I mean at least mountains and basins) at reasonable frames (I believe it since the shader is only applied to a small surface [about 10X10BU]). Also if there is a way to map it (the D map) according to another object, instead of using expensive maths to accomplish the effect…
-
Why not? It might just be a nice way to fake terrain LOD! I’m trying as many techniques as I can think of to accomplish high detail on planet surfaces. It saves game space as well a high detail DM is cheaper in size than a high detail mesh. I wanted to go as far as asking procedural heigh maps (like the ones on the realtime procedural clouds demo by Martinsh) but, I really need to control the collision structure…
Thank you very much for your valuable opinions!