Sign in to follow this  

POM on geoemtry above camera

This topic is 3936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im having some problems with POM on objects that are above the camera... for example when looking up on a hill... any ideas how this can be solved? Image Hosted by ImageShack.us

Share this post


Link to post
Share on other sites
I'm unsure what POM is, but this looks quite a bit like a voxel rendering. Could you please provide more details?

Share this post


Link to post
Share on other sites
I think it would be a good idea to post your shader code. It's very hard to judge what is going on from just the picture.

Share this post


Link to post
Share on other sites
hmm thats weird... i htought i posted it.. anyways here it is.... ive removed some of the irrelevant code.. im using a small hack for terrain to get the TBN.. dunno if its correct though


//VERTEX
#version 110

uniform sampler2D heightmap;

uniform vec3 CamPos;
varying vec3 ViewVec;
varying vec3 vertPos;
varying vec2 ParallaxOffsetVec;

void main()
{
vec3 WorldPos = gl_Vertex.xyz;
ViewVec = CamPos.xyz - WorldPos.xyz;

vec2 ParallaxDirection = normalize(ViewVec.xz);
float L = length(ViewVec);
float ParallaxLength = sqrt(L * L - ViewVec.y * ViewVec.y) / ViewVec.y;
ParallaxOffsetVec = ParallaxDirection * ParallaxLength;
ParallaxOffsetVec *= 0.00018;

gl_Position = gl_ModelViewProjectionMatrix * vec4(WorldPos, 1.0);
vertPos = gl_ModelViewMatrix * vec4(WorldPos, 1.0);
}


//FRAGMENT
#version 110

uniform sampler2D TextureMap;
uniform sampler2D NormalMap;
uniform sampler2D DetailMap;

varying vec2 ParallaxOffsetVec;
varying vec3 ViewVec;
varying vec3 VertPos;

mat3 GetTBN()
{
vec3 Normal = texture2D(NormalMap, gl_TexCoord[0].st).rgb*2.0-1.0;
vec3 Tangent = cross(Normal,vec3(0.0,0.0,1.0));
vec3 Binormal = cross(Normal,vec3(-1.0,0.0,0.0));
return mat3((Tangent), (Binormal), (Normal));
}

vec2 parallax(vec3 N, vec3 V, vec2 TexCoord)
{
int numSteps = (int)mix(20, 8, dot(V,N));

float CurHeight = 0.0;
float PrevHeight = 1.0;
float NextHeight = 0.0;

float StepSize = 1.0 / (float)numSteps;

vec2 TexOffsetPerStep = StepSize*ParallaxOffsetVec;
vec2 TexCurrentOffset = TexCoord;
float CurrentBound = 1.0;

vec2 p1 = 0;
vec2 p2 = 0;

vec2 TexOffset = 0;

for(int i = 0; i < numSteps; i++)
{
TexCurrentOffset -= TexOffsetPerStep;
CurHeight = texture2D(DetailMap, TexCurrentOffset*30).g+0.0000001;

CurrentBound -= StepSize;

if (CurHeight > CurrentBound)
{
p1 = vec2(CurrentBound, CurHeight);
p2 = vec2(CurrentBound+StepSize, PrevHeight);

TexOffset = TexCurrentOffset - TexOffsetPerStep;

i = numSteps + 1;
}

PrevHeight = CurHeight;

}

float Delta2 = p2.x - p2.y;
float Delta1 = p1.x - p1.y;

float ParallaxAmount = (p1.x * Delta2 - p2.x * Delta1) / (Delta2 - Delta1);

vec2 ParallaxOffset = ParallaxOffsetVec * (1.0 - ParallaxAmount);

return TexCoord - ParallaxOffset;

}

void main()
{
vec2 TexCoord = gl_TexCoord[0].st;

mat3 TBN = GetTBN();

vec3 nViewVec = normalize(ViewVec)*TBN;

vec2 NewTexCoord = parallax(vec3(0.0, 1.0,0.0)*TBN,nViewVec, TexCoord);

vec4 Color = texture2D(TextureMap,NewTexCoord)*texture2D(DetailMap,NewTexCoord*30).g;

gl_FragColor = vec4(Color);
}








[Edited by - Dragon_Strike on April 9, 2007 4:26:32 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this