Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glsl: deduplicate RayIntersectDisplaceMap #173

Merged
merged 1 commit into from Mar 4, 2019

Conversation

illwieckz
Copy link
Member

RayIntersectDisplaceMap is already defined in reliefMapping_fp.glsl, doing the exact same thing:

float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
{
const int linearSearchSteps = 16;
const int binarySearchSteps = 6;
float depthStep = 1.0 / float(linearSearchSteps);
// current size of search window
float size = depthStep;
// current depth position
float depth = 0.0;
// best match found (starts with last position 1.0)
float bestDepth = 1.0;
// search front to back for first point inside object
for(int i = 0; i < linearSearchSteps - 1; ++i)
{
depth += size;
vec4 t = texture2D(normalMap, dp + ds * depth);
if(bestDepth > 0.996) // if no depth found yet
if(depth >= t.w)
bestDepth = depth; // store best depth
}
depth = bestDepth;
// recurse around first point (depth) for closest match
for(int i = 0; i < binarySearchSteps; ++i)
{
size *= 0.5;
vec4 t = texture2D(normalMap, dp + ds * depth);
if(depth >= t.w)
#ifdef RM_DOUBLEDEPTH
if(depth <= t.z)
#endif
{
bestDepth = depth;
depth -= 2.0 * size;
}
depth += size;
}
return bestDepth;
}

@illwieckz illwieckz changed the title deduplicate RayIntersectDisplaceMap glsl: deduplicate RayIntersectDisplaceMap Mar 3, 2019
@slipher
Copy link
Member

slipher commented Mar 3, 2019

It would be good to make sure that the liquid shader is actually used first (see my comment on #172).

@illwieckz
Copy link
Member Author

illwieckz commented Mar 3, 2019

If the liquid shader is not used, it would explain #120

incorrect

@illwieckz
Copy link
Member Author

Hmm no, commenting out the #if !defined( GLSL_COMPILE_STARTUP_ONLY ) test does not fix that water issue, this is probably not related.

@slipher
Copy link
Member

slipher commented Mar 4, 2019

I checked my copy of station15 1.1 and it doesn't actually use the liquidMap keyword, which is required to activate these code paths. So no help in showing whether the code is used or works. Do you know some map that actually uses a liquidMap shader stage?

@illwieckz
Copy link
Member Author

I think no one map use liquidStage yet. Like parallax, it's maybe entirely broken no one knows…
By the way the change is very straightforward, in any way it's better to have a cleaner code even if it's a dead code. This is to be sure any fix done to that parallax code is forwarded everywhere it is used. By deduplicating we make sure a potentially fixed bug will not resurface the day this code will be live again.

it's already defined in reliefMapping_fp.glsl
@illwieckz illwieckz merged commit b0453e2 into DaemonEngine:master Mar 4, 2019
@illwieckz illwieckz deleted the rayintersect branch January 18, 2020 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants