2011-05-23 23:42:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Input textures
|
2012-08-19 18:35:10 +00:00
|
|
|
uniform sampler2D landscapeTex[2];
|
2011-05-23 23:42:51 +00:00
|
|
|
uniform sampler2D scalerTex;
|
|
|
|
uniform sampler3D materialTex;
|
|
|
|
|
|
|
|
// Resolution of the landscape texture
|
|
|
|
uniform vec2 resolution;
|
|
|
|
|
2012-08-19 18:35:10 +00:00
|
|
|
// Center position
|
|
|
|
uniform vec2 center;
|
2011-05-23 23:42:51 +00:00
|
|
|
// Texture map
|
2012-11-05 16:10:55 +00:00
|
|
|
#ifndef NO_BROKEN_ARRAYS_WORKAROUND
|
2011-05-28 14:18:40 +00:00
|
|
|
uniform sampler1D matMapTex;
|
2011-07-03 18:34:54 +00:00
|
|
|
#else
|
|
|
|
uniform float matMap[256];
|
|
|
|
#endif
|
2011-05-28 14:18:40 +00:00
|
|
|
uniform int materialDepth;
|
2012-11-05 16:50:59 +00:00
|
|
|
uniform vec2 materialSize;
|
2011-05-23 23:42:51 +00:00
|
|
|
|
|
|
|
// Expected parameters for the scaler
|
|
|
|
const vec2 scalerStepX = vec2(1.0 / 8.0, 0.0);
|
|
|
|
const vec2 scalerStepY = vec2(0.0, 1.0 / 32.0);
|
2011-07-24 21:50:52 +00:00
|
|
|
const vec2 scalerOffset = scalerStepX / 3.0 + scalerStepY / 3.0;
|
2011-05-23 23:42:51 +00:00
|
|
|
const vec2 scalerPixel = vec2(scalerStepX.x, scalerStepY.y) / 3.0;
|
|
|
|
|
2015-01-01 15:04:21 +00:00
|
|
|
// Parameters
|
|
|
|
|
|
|
|
// how much % the normals from the normal map are added up to the landscape normal. The higher the strength, the more
|
|
|
|
// structure within the material is visible but also the less the borders between the different materials stand out.
|
|
|
|
const float normalMapStrength = 0.75;
|
|
|
|
|
2011-05-28 14:18:40 +00:00
|
|
|
float queryMatMap(int pix)
|
|
|
|
{
|
2012-11-05 16:10:55 +00:00
|
|
|
#ifndef NO_BROKEN_ARRAYS_WORKAROUND
|
2011-07-03 18:34:54 +00:00
|
|
|
int idx = f2i(texture1D(matMapTex, float(pix) / 256.0 + 0.5 / 256.0).r);
|
2011-08-20 00:25:08 +00:00
|
|
|
return float(idx) / 256.0 + 0.5 / float(materialDepth);
|
2011-05-28 14:18:40 +00:00
|
|
|
#else
|
|
|
|
return matMap[pix];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(coordinate)
|
2011-05-23 23:42:51 +00:00
|
|
|
{
|
|
|
|
// full pixel steps in the landscape texture (depends on landscape resolution)
|
|
|
|
vec2 fullStep = vec2(1.0, 1.0) / resolution;
|
|
|
|
vec2 fullStepX = vec2(fullStep.x, 0.0);
|
|
|
|
vec2 fullStepY = vec2(0.0, fullStep.y);
|
|
|
|
|
2012-08-19 18:35:10 +00:00
|
|
|
vec2 texCoo = gl_TexCoord[0].st;
|
2014-11-20 10:52:14 +00:00
|
|
|
|
2011-05-23 23:42:51 +00:00
|
|
|
// calculate pixel position in landscape, find center of current pixel
|
2012-08-19 18:35:10 +00:00
|
|
|
vec2 pixelCoo = texCoo * resolution;
|
2011-05-23 23:42:51 +00:00
|
|
|
vec2 centerCoo = (floor(pixelCoo) + vec2(0.5, 0.5)) / resolution;
|
|
|
|
|
2014-11-20 10:52:14 +00:00
|
|
|
// Texture coordinate for material
|
|
|
|
vec2 materialCoo = texCoo * resolution / materialSize;
|
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(texture)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
2012-09-16 09:15:30 +00:00
|
|
|
// our pixel color (without/with interpolation)
|
|
|
|
vec4 landscapePx = texture2D(landscapeTex[0], centerCoo);
|
|
|
|
vec4 realLandscapePx = texture2D(landscapeTex[0], texCoo);
|
2014-11-20 10:52:14 +00:00
|
|
|
}
|
2011-05-23 23:42:51 +00:00
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(material)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
2012-08-19 18:35:10 +00:00
|
|
|
|
2011-05-28 14:18:40 +00:00
|
|
|
// Get material pixels
|
2012-09-16 09:15:30 +00:00
|
|
|
float materialIx = queryMatMap(f2i(landscapePx.r));
|
2014-11-20 10:52:14 +00:00
|
|
|
vec4 materialPx = texture3D(materialTex, vec3(materialCoo, materialIx));
|
|
|
|
vec4 normalPx = texture3D(materialTex, vec3(materialCoo, materialIx+0.5));
|
2012-09-05 20:51:25 +00:00
|
|
|
|
2014-11-20 10:52:14 +00:00
|
|
|
// Same for second pixel, but we'll simply use the first normal
|
2015-09-10 23:44:23 +00:00
|
|
|
#ifdef OC_HAVE_2PX
|
2014-11-20 10:52:14 +00:00
|
|
|
float materialIx2 = queryMatMap(f2i(landscapePx2.r));
|
|
|
|
vec4 materialPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2));
|
2014-11-20 20:44:11 +00:00
|
|
|
vec4 normalPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2+0.5));
|
2014-11-20 10:52:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
2012-09-16 09:15:30 +00:00
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(normal)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
2012-09-16 09:15:30 +00:00
|
|
|
// Normal calculation
|
2014-11-20 10:52:14 +00:00
|
|
|
vec3 normal = extend_normal(mix(realLandscapePx.yz, landscapePx.yz, scalerPx.a)
|
|
|
|
- vec2(0.5, 0.5));
|
2012-09-16 09:15:30 +00:00
|
|
|
vec3 textureNormal = normalPx.xyz - vec3(0.5,0.5,0.5);
|
2015-01-01 15:04:21 +00:00
|
|
|
normal = normal + textureNormal * normalMapStrength;
|
2014-11-20 10:52:14 +00:00
|
|
|
|
2015-09-10 23:44:23 +00:00
|
|
|
#ifdef OC_HAVE_2PX
|
2014-11-20 10:52:14 +00:00
|
|
|
vec3 normal2 = extend_normal(landscapePx2.yz - vec2(0.5, 0.5));
|
2014-11-20 20:44:11 +00:00
|
|
|
vec3 textureNormal2 = normalPx2.xyz - vec3(0.5,0.5,0.5);
|
2015-01-01 15:04:21 +00:00
|
|
|
normal2 = normal2 + textureNormal2 * normalMapStrength;
|
2014-11-20 10:52:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(color) {
|
2014-11-20 10:52:14 +00:00
|
|
|
#define color gl_FragColor
|
|
|
|
color = materialPx;
|
2015-09-10 23:44:23 +00:00
|
|
|
#ifdef OC_HAVE_2PX
|
2014-11-20 10:52:14 +00:00
|
|
|
vec4 color2 = materialPx2;
|
|
|
|
#endif
|
2011-05-24 09:29:08 +00:00
|
|
|
}
|