mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-15 06:22:03 +01:00
Shader debugging: scaling the world
In the linearizeDepth function in area_effect.frag, I was multiplying by 2, but the scaling of the world was off. The number I found that works best is e - 0.99, and I have no idea why.
This commit is contained in:
parent
7988fb69a7
commit
f12d9452b4
3 changed files with 44 additions and 16 deletions
|
@ -100,8 +100,8 @@ public class EffectsHandler {
|
||||||
program.bindDepthTexture(mainBuffer.getDepthAttachment());
|
program.bindDepthTexture(mainBuffer.getDepthAttachment());
|
||||||
|
|
||||||
GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer;
|
GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer;
|
||||||
Matrix4f projection = gameRenderer.getBasicProjectionMatrix(gameRenderer.getActiveRenderInfo(), AnimationTickHolder.getPartialTicks(), true);
|
//Matrix4f projection = gameRenderer.getBasicProjectionMatrix(gameRenderer.getActiveRenderInfo(), AnimationTickHolder.getPartialTicks(), true);
|
||||||
//Matrix4f projection = Backend.projectionMatrix.copy();
|
Matrix4f projection = Backend.projectionMatrix.copy();
|
||||||
//projection.a23 = projection.a32 = 0;
|
//projection.a23 = projection.a32 = 0;
|
||||||
projection.a33 = 1;
|
projection.a33 = 1;
|
||||||
projection.invert();
|
projection.invert();
|
||||||
|
@ -117,6 +117,9 @@ public class EffectsHandler {
|
||||||
// Vector3d pos3 = new Vector3d(906, 84, -207);
|
// Vector3d pos3 = new Vector3d(906, 84, -207);
|
||||||
Vector3d cameraPos = gameRenderer.getActiveRenderInfo().getProjectedView();
|
Vector3d cameraPos = gameRenderer.getActiveRenderInfo().getProjectedView();
|
||||||
|
|
||||||
|
program.setTestParam((float) (Math.E - 0.99));
|
||||||
|
program.setCameraPos(cameraPos.inverse());
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
double angle = (Math.PI * AnimationTickHolder.getRenderTime() / 40) + i * Math.PI / 4;
|
double angle = (Math.PI * AnimationTickHolder.getRenderTime() / 40) + i * Math.PI / 4;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,9 @@ public class SphereFilterProgram extends GlProgram {
|
||||||
|
|
||||||
protected final int uNearPlane;
|
protected final int uNearPlane;
|
||||||
protected final int uFarPlane;
|
protected final int uFarPlane;
|
||||||
|
|
||||||
|
protected final int uCameraPos;
|
||||||
|
protected final int testParam;
|
||||||
// protected final int uSphereCenter;
|
// protected final int uSphereCenter;
|
||||||
// protected final int uSphereRadius;
|
// protected final int uSphereRadius;
|
||||||
// protected final int uSphereFeather;
|
// protected final int uSphereFeather;
|
||||||
|
@ -62,6 +65,8 @@ public class SphereFilterProgram extends GlProgram {
|
||||||
uInverseView = getUniformLocation("uInverseView");
|
uInverseView = getUniformLocation("uInverseView");
|
||||||
uNearPlane = getUniformLocation("uNearPlane");
|
uNearPlane = getUniformLocation("uNearPlane");
|
||||||
uFarPlane = getUniformLocation("uFarPlane");
|
uFarPlane = getUniformLocation("uFarPlane");
|
||||||
|
uCameraPos = getUniformLocation("uCameraPos");
|
||||||
|
testParam = getUniformLocation("testParam");
|
||||||
//
|
//
|
||||||
// uSphereCenter = getUniformLocation("uSphereCenter");
|
// uSphereCenter = getUniformLocation("uSphereCenter");
|
||||||
// uSphereRadius = getUniformLocation("uSphereRadius");
|
// uSphereRadius = getUniformLocation("uSphereRadius");
|
||||||
|
@ -82,6 +87,14 @@ public class SphereFilterProgram extends GlProgram {
|
||||||
GL20.glUniform1f(uFarPlane, farPlane);
|
GL20.glUniform1f(uFarPlane, farPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTestParam(float farPlane) {
|
||||||
|
GL20.glUniform1f(testParam, farPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCameraPos(Vector3d pos) {
|
||||||
|
GL20.glUniform3f(uCameraPos, (float) pos.x, (float) pos.y, (float) pos.z);
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
filters.clear();
|
filters.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,12 @@ uniform sampler2D uDepth;
|
||||||
uniform sampler2D uColor;
|
uniform sampler2D uColor;
|
||||||
uniform float uNearPlane = 0.15;
|
uniform float uNearPlane = 0.15;
|
||||||
uniform float uFarPlane = 1.;
|
uniform float uFarPlane = 1.;
|
||||||
|
uniform vec3 uCameraPos;
|
||||||
|
|
||||||
|
uniform float testParam = 2.0;
|
||||||
|
|
||||||
|
uniform mat4 uInverseProjection;
|
||||||
|
uniform mat4 uInverseView;
|
||||||
|
|
||||||
struct SphereFilter {
|
struct SphereFilter {
|
||||||
vec4 sphere;// <vec3 position, float radius>
|
vec4 sphere;// <vec3 position, float radius>
|
||||||
|
@ -26,8 +32,9 @@ layout (std140) uniform Filters {
|
||||||
};
|
};
|
||||||
|
|
||||||
float linearizeDepth(float d, float zNear, float zFar) {
|
float linearizeDepth(float d, float zNear, float zFar) {
|
||||||
float z_n = 2.0 * d - 1.0;
|
float clipZ = 2.0 * d - 1.0;
|
||||||
return 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear));
|
float linearized = zNear * zFar / (zFar + zNear - clipZ * (zFar - zNear));
|
||||||
|
return testParam * linearized;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 filterColor(mat4 colorOp, vec4 frag) {
|
vec4 filterColor(mat4 colorOp, vec4 frag) {
|
||||||
|
@ -41,7 +48,7 @@ float getDepth() {
|
||||||
float depth = texture2D(uDepth, ScreenCoord).r;
|
float depth = texture2D(uDepth, ScreenCoord).r;
|
||||||
|
|
||||||
depth = linearizeDepth(depth, uNearPlane, uFarPlane);
|
depth = linearizeDepth(depth, uNearPlane, uFarPlane);
|
||||||
//depth = ( - uNearPlane) / (uFarPlane - uNearPlane);
|
//depth = (depth - uNearPlane) / (uFarPlane - uNearPlane);
|
||||||
//depth = depth / uFarPlane;
|
//depth = depth / uFarPlane;
|
||||||
|
|
||||||
return depth;
|
return depth;
|
||||||
|
@ -49,19 +56,24 @@ float getDepth() {
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float depth = getDepth();
|
float depth = getDepth();
|
||||||
vec3 worldPos = WorldDir * depth;
|
vec3 worldPos = WorldDir * depth - uCameraPos;
|
||||||
|
|
||||||
vec4 accum = texture2D(uColor, ScreenCoord);
|
vec4 diffuse = texture2D(uColor, ScreenCoord);
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < uCount; i++) {
|
||||||
|
// SphereFilter s = uSpheres[i];
|
||||||
|
//
|
||||||
|
// float distance = distance(s.sphere.xyz, worldPos);
|
||||||
|
// float strength = 1 - smoothstep(s.sphere.w - s.feather, s.sphere.w + s.feather, distance);
|
||||||
|
//
|
||||||
|
// accum = mix(accum, filterColor(s.colorOp, accum), strength);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Color = accum;
|
||||||
|
|
||||||
for (int i = 0; i < uCount; i++) {
|
vec3 fractionalCoords = fract(worldPos);
|
||||||
SphereFilter s = uSpheres[i];
|
|
||||||
|
|
||||||
float distance = distance(s.sphere.xyz, worldPos);
|
vec3 isBonudary = step(15./16., fractionalCoords);
|
||||||
float strength = 1 - smoothstep(s.sphere.w - s.feather, s.sphere.w + s.feather, distance);
|
|
||||||
|
|
||||||
accum = mix(accum, filterColor(s.colorOp, accum), strength);
|
Color = vec4(mix(diffuse.rgb, fractionalCoords, isBonudary), 1.);
|
||||||
}
|
|
||||||
|
|
||||||
Color = accum;
|
|
||||||
//Color = vec4(vec3(distance / uFarPlane), 1.);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue