Posted: Fri Nov 21, 2008 11:54 pm
lol. yeah. i meant the normal mapping, not the brick work - excellent as it may be.
For information and discussion about Oolite.
https://bb.oolite.space/
and planets and moons and also .......Griff wrote:Can't wait to see oolite normal mapped asteroids!
Code: Select all
attribute vec3 tangent; // Provided by Oolite
//...
void main(void)
{
// Build tangent basis
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * tangent);
vec3 b = cross(n, t);
mat3 TBN = mat3(t, b, n);
Code: Select all
vec3 eyeVector = -vec3(gl_ModelViewMatrix * gl_Vertex);
vEyeVector = eyeVector * TBN;
vec3 light0Vector = gl_LightSource[0].position.xyz + eyeVector;
vLight0Vector = light0Vector * TBN;
vec3 light1Vector = gl_LightSource[1].position.xyz + eyeVector;
vLight1Vector = light1Vector * TBN;
Code: Select all
vTexCoord = gl_MultiTexCoord0.st;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
Additionally, the expression -reflect(lightVector, normal) simplifies to vec3(-lightVector.x, -lightVector.y, lightVector.z).Proof wrote:By definition, dot(u, v) is equivalent to u.x * v.x + u.y * v.y + u.z * v.z.
Given u = (0, 0, 1), we get v.x * 0 + v.y * 0 + v.z * 1 = v.z.
Since the surface normal is a constant, normal mapping is simply implemented by replacing it with a value from the normal map texture.Proof wrote:By definition, reflect(v, n) is eqivalent to v - 2.0 * dot(n, v) * n.
Given n = (0, 0, 1), we get:
v - 2.0 * v.z * (0, 0, 1) [see previous proof]
= v - (0, 0, 2.0 * v.z)
= (v.x, v.y, -v.z)
The negation is of course (-v.x, -v.y, v.z).
Code: Select all
#if OOSTD_NORMAL_MAP // Defined to 1 by Oolite if a normal map is to be used
vec3 normal = texture2D(uNormalMap, texCoord).rgb;
#else
const vec3 normal = vec3(0.0, 0.0, 1.0);
#endif
Code: Select all
#if OOSTD_NORMAL_AND_PARALLAX_MAP
float parallax = texture2D(uNormalMap, vTexCoord).a;
parallax = parallax * uParallaxScale + uParallaxBias;
vec2 texCoord = vTexCoord - parallax * eyeVector.xy * vec2(-1.0, 1.0);
#else
#define texCoord vTexCoord
#endif
Code: Select all
vec4 CalcDiffuseLight(in vec3 lightVector, in vec3 normal, in vec4 lightColor)
{
#if OOSTD_NORMAL_MAP
float intensity = dot(normal, lightVector);
#else
float intensity = lightVector.z;
#endif
intensity = max(intensity, 0.0);
return lightColor * intensity;
}
vec4 CalcSpecularLight(in vec3 lightVector, in vec3 eyeVector, in float exponent, in vec3 normal, in vec4 lightColor)
{
#if OOSTD_NORMAL_MAP
vec3 reflection = -reflect(lightVector, normal);
#else
vec3 reflection = vec3(-lightVector.x, -lightVector.y, lightVector.z);
#endif
float intensity = dot(reflection, eyeVector);
intensity = pow(max(intensity, 0.0), exponent);
return lightColor * intensity;
}
...
diffuseLight += CalcDiffuseLight(light1Vector, normal, gl_LightSource[1].diffuse);
specularLight += CalcSpecularLight(light1Vector, eyeVector, exponent, normal, gl_LightSource[1].specular);
I second this petition to Ahruman! (You're free to re-phrase, of course.)DaddyHoggy wrote:No longer can you avoid the title "God of Modelling" - even if you claim to do it all by accident and theft!
Code: Select all
if (gl_Vertex.x > 0.0)
TBN = mat3(-t, b, n);
Matrix maths hurts my brain, but that’ll probably work… for faces whose vertices are entirely on one side of the dividing line. It definitely won’t work for anything that crosses the border. To fix that, there are two options:Griff wrote:tried to fix the mirrored UV's causing the lighting to appear wrong effect by adding this to the vertex shader - please feel free to point and laugh:
Here’s a basic implementation:Ahruman wrote:Shader idea: a moving-blotch camo texture, along the lines of Rorschach’s mask in Watchmen. Could probably be done along the lines of the Freaky Thargoids shader.Griff wrote:cowprint texture
Code: Select all
uniform sampler2D tex;
uniform float uTime;
const float k2Pi = 6.283185307179586;
const float kTimeRate = 0.1;
const float kSharpen = 40.0;
const float kBias = -2.0;
// 5.0 is the total magnitude of n1..n3 times two.
const float kScaledSharpen = kSharpen / 5.0;
const vec3 color1 = vec3(0.05, 0.05, 0.15);
const vec3 color2 = vec3(0.3, 0.05, 0.05);
float Noise(vec3 sample)
{
float n1 = 0.0, n2 = 0.0, n3 = 0.0;
float time = uTime * kTimeRate;
n1 = sin(sample.r * k2Pi + time);
n2 = sin(sample.g * k2Pi * 3.0 + time * 1.003) * 0.5;
n3 = sin(sample.b * k2Pi + time * 2.0);
float n = (n1 + n2 + n3);
n = smoothstep(0.0, 1.0, n * kScaledSharpen + kBias + 0.5);
return n;
}
void main()
{
vec3 sample = texture2D(tex, gl_TexCoord[0].st).rgb;
float n = Noise(sample);
vec3 diffuseColor = mix(color1, color2, n);
gl_FragColor = vec4(diffuseColor, 1.0);
}
Code: Select all
sample.r = texture2D(tex, gl_TexCoord[0].st + vec2(0.01, 0.005) * uTime).r;
sample.g = texture2D(tex, gl_TexCoord[0].st + vec2(0.013, -0.02) * uTime).g;
sample.b = texture2D(tex, gl_TexCoord[0].st + vec2(-0.008, 0.017) * uTime).b;