Split: Planet rendering issues
Moderators: winston, another_commander, Getafix
Re: Split: Planet rendering issues
Playing around with the planet fragment shader, it's looking very much as if the vLight1Vector parameter that's passed to it is always normal to the surface, which wouldn't be right. I haven't got as far as finding out where this parameter comes from though. I'll keep digging.
Re: Split: Planet rendering issues
It's set in the vertex shader.kanthoney wrote:Playing around with the planet fragment shader, it's looking very much as if the vLight1Vector parameter that's passed to it is always normal to the surface, which wouldn't be right. I haven't got as far as finding out where this parameter comes from though. I'll keep digging.
Re: Split: Planet rendering issues
Looking at the vertex shader:
Let's see if I've got this right. The lighting is in eye space, so the normal needs to be transformed to eye space, which is what the vec3 normal = ... line does. Then a basis for the tangent space is constructed.
The fragment shader expects everything to be in this tangent space, which is what I think the *TBN is for - but wouldn't you have to multiply by the inverse of TBN?
Code: Select all
varying vec3 vEyeVector;
varying vec2 vTexCoords;
varying vec3 vLight1Vector;
varying vec3 vCoords;
void main(void)
{
vCoords = gl_Vertex.xyz;
// Build tangent basis.
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
vec3 binormal = cross(normal, gl_NormalMatrix * vec3(0, 1, 0));
vec3 tangent = -cross(normal, binormal);
mat3 TBN = mat3(tangent, binormal, normal);
vec3 eyeVector = -vec3(gl_ModelViewMatrix * gl_Vertex);
vEyeVector = eyeVector;
vec3 light1Vector = gl_LightSource[1].position.xyz + eyeVector;
vLight1Vector = light1Vector;
vTexCoords = gl_MultiTexCoord0.st;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
The fragment shader expects everything to be in this tangent space, which is what I think the *TBN is for - but wouldn't you have to multiply by the inverse of TBN?
Re: Split: Planet rendering issues
Hard terminator with slight reddish-orange tinge? Nailed yer!
I was right, except instead of inverting TBN (which would require a matrix inversion every vertex - not quick) I've pushed TBN to the fragment shader and done everything in eye space there instead. I'll submit a fix tomorrow once I've tidied stuff up a bit.
I was right, except instead of inverting TBN (which would require a matrix inversion every vertex - not quick) I've pushed TBN to the fragment shader and done everything in eye space there instead. I'll submit a fix tomorrow once I've tidied stuff up a bit.
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Re: Split: Planet rendering issues
If we’re happy with the new detail settings, we should remove all references toanother_commander wrote:Oops. Hadn't realized that was the case. Please disregard my earlier comment then.cim wrote:For planets, Normal Shaders just uses the static pre-shader methods - the shader program is never even executed. There isn't currently any way that the OO_REDUCED_DETAIL code path can be run.another_commander wrote:This gets to use the same smoothstep code for the terminator in both Normal Shaders and Extra Detail settings.
OO_REDUCED_DETAIL
.E-mail: [email protected]
Re: Split: Planet rendering issues
Now I'm baffled again. Changing the specular part of the fragment shader has no effect at all - even turning it off. The shader is loading, because I can make the planet all sorts of pretty colours. Also, commenting out all the bits that change totalColor (or setting gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0)) turns off the clouds but not the planet - I take it that's not right?
Re: Split: Planet rendering issues
Also: Lave.
Lave from the same position, having rolled 180.
So maybe a little work still needed in places...
Lave from the same position, having rolled 180.
So maybe a little work still needed in places...
Re: Split: Planet rendering issues
Pretty!
Looks like I needed to transpose the matrix vTBN, i.e.
in the vertex shader. I've pushed that to master.
Looks like I needed to transpose the matrix vTBN, i.e.
Code: Select all
vTBN = transpose(mat3(tangent, binormal, vNormal));
Re: Split: Planet rendering issues
That works, and it looks like the specular highlight is in the right place again, as well.
- submersible
- Commodore
- Posts: 264
- Joined: Thu Nov 10, 2011 7:49 am
Re: Split: Planet rendering issues
Also for me the pinched lighting at the poles has gone. I wonder if the trouble I've been having with shading the atmosphere is related , since I've copied liberally from the planet shaders.cim wrote:That works, and it looks like the specular highlight is in the right place again, as well.
Povray Planets - Planet textures for your galaxy
Re: Split: Planet rendering issues
Something was bugging me about this, so I've been investigating further - turns out the problem wasn't what I thought it was. The actual problem is that gl_NormalMatrix is zero for some openGL implementations, which means both the tangent and binormal vectors are zero. In the original shader, this had the effect of projecting out the component of the light vector parallel to the normal, causing the fragment shader to think the light source was always directly above (or below) the fragment, illuminating it fully on the day side and not at all on the night side.
The effect of moving the TBN matrix to the fragment shader was to project out the z-component of the normal map instead of the light position, which sort-of works if you're not bothered about the x and y components of the normal map.
The effect of moving the TBN matrix to the fragment shader was to project out the z-component of the normal map instead of the light position, which sort-of works if you're not bothered about the x and y components of the normal map.
Re: Split: Planet rendering issues
Apparently Lave is supposed to look like this, except presumably with more of a shadow. And that really is a snooker ball.
Re: Split: Planet rendering issues
Actually, that's what Lave looks like if you put the light source *really* close.
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
Re: Split: Planet rendering issues
wow guys, that's really starting to look fantastic. it doesn't bother me that the specular highlight is so pronounced, except maybe that square shaped one just to the right of the main specular highlight looks a bit odd,still though fantastic work, just needs the atmosphere effect from submersibles shady planets branch and some city lights on the dark side of the planet and it would be perfect
Wiki homepage for my OXP: http://wiki.alioth.net/index.php/Griff_Industries
Re: Split: Planet rendering issues
Unfortunately, that was a mistake. A damn cool looking mistake, mind!