More reflection raymarching.
This commit is contained in:
parent
d33d10313c
commit
d2c5bfcbb1
|
@ -11,6 +11,10 @@ import lue.node.CameraNode;
|
|||
|
||||
class FirstPersonController extends Trait {
|
||||
|
||||
#if (!WITH_PHYSICS)
|
||||
public function new() { super(); }
|
||||
#else
|
||||
|
||||
var transform:Transform;
|
||||
var body:RigidBody;
|
||||
var camera:CameraNode;
|
||||
|
@ -64,8 +68,8 @@ class FirstPersonController extends Trait {
|
|||
// Look
|
||||
// if (!locked) {
|
||||
if (Input.touch) {
|
||||
camera.rotate(new Vec4(1, 0, 0), Input.deltaY / 100);
|
||||
transform.rotate(new Vec4(0, 0, 1), -Input.deltaX / 100);
|
||||
camera.rotate(new Vec4(1, 0, 0), Input.deltaY / 200);
|
||||
transform.rotate(new Vec4(0, 0, 1), -Input.deltaX / 200);
|
||||
body.syncTransform();
|
||||
}
|
||||
|
||||
|
@ -153,4 +157,5 @@ class FirstPersonController extends Trait {
|
|||
|
||||
camera.updateMatrix();
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class PhysicsDrag extends Trait {
|
|||
|
||||
if (b != null && b.mass > 0 && !b.body.value.isKinematicObject()) {
|
||||
|
||||
updateRays();
|
||||
setRays();
|
||||
pickedBody = b;
|
||||
|
||||
#if js
|
||||
|
@ -107,7 +107,7 @@ class PhysicsDrag extends Trait {
|
|||
|
||||
if (pickConstraint != null) {
|
||||
|
||||
updateRays();
|
||||
setRays();
|
||||
|
||||
// Keep it at the same picking distance
|
||||
var btRayTo = BtVector3.create(rayTo.value.x(), rayTo.value.y(), rayTo.value.z());
|
||||
|
@ -135,7 +135,7 @@ class PhysicsDrag extends Trait {
|
|||
}
|
||||
}
|
||||
|
||||
inline function updateRays() {
|
||||
inline function setRays() {
|
||||
rayFrom = physics.getRayFrom();
|
||||
rayTo = physics.getRayTo(Input.x, Input.y);
|
||||
}
|
||||
|
|
|
@ -2263,16 +2263,19 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
|
|||
def make_texture(self, id, image_node):
|
||||
tex = Object()
|
||||
tex.id = id
|
||||
tex.name = image_node.image.name.rsplit('.', 1)[0] # Remove extension
|
||||
tex.name = tex.name.replace('.', '_')
|
||||
if image_node.interpolation == 'Cubic': # Mipmap linear
|
||||
tex.mipmap_filter = 'linear'
|
||||
tex.generate_mipmaps = True
|
||||
elif image_node.interpolation == 'Smart': # Mipmap anisotropic
|
||||
tex.min_filter = 'anisotropic'
|
||||
tex.mipmap_filter = 'linear'
|
||||
tex.generate_mipmaps = True
|
||||
#image_node.extension = 'Repeat'
|
||||
if image_node.image is not None:
|
||||
tex.name = image_node.image.name.rsplit('.', 1)[0] # Remove extension
|
||||
tex.name = tex.name.replace('.', '_')
|
||||
if image_node.interpolation == 'Cubic': # Mipmap linear
|
||||
tex.mipmap_filter = 'linear'
|
||||
tex.generate_mipmaps = True
|
||||
elif image_node.interpolation == 'Smart': # Mipmap anisotropic
|
||||
tex.min_filter = 'anisotropic'
|
||||
tex.mipmap_filter = 'linear'
|
||||
tex.generate_mipmaps = True
|
||||
#image_node.extension = 'Repeat'
|
||||
else:
|
||||
tex.name = ''
|
||||
return tex
|
||||
|
||||
def parse_material_surface(self, material, c, defs, tree, node):
|
||||
|
|
|
@ -51,9 +51,9 @@ os.chdir('../fisheye_pass')
|
|||
make_resources.make('fisheye_pass.shader.json')
|
||||
make_variants.make('fisheye_pass.shader.json')
|
||||
|
||||
# os.chdir('../ssr_pass')
|
||||
# make_resources.make('ssr_pass.shader.json')
|
||||
# make_variants.make('ssr_pass.shader.json')
|
||||
os.chdir('../ssr_pass')
|
||||
make_resources.make('ssr_pass.shader.json')
|
||||
make_variants.make('ssr_pass.shader.json')
|
||||
|
||||
os.chdir('../combine_pass')
|
||||
make_resources.make('combine_pass.shader.json')
|
||||
|
|
|
@ -138,7 +138,7 @@ void main() {
|
|||
|
||||
vec4 g1 = texture(gbuffer1, texCoord); // Positions, roughness
|
||||
vec4 g2 = texture(gbuffer2, texCoord); // Base color, metalness
|
||||
float ao = texture(ssaotex, texCoord).r; // Normals, depth
|
||||
float ao = texture(ssaotex, texCoord).r;
|
||||
|
||||
vec3 n = g0.rgb;
|
||||
vec3 p = g1.rgb;
|
||||
|
@ -193,6 +193,8 @@ void main() {
|
|||
// outColor.rgb *= occlusion;
|
||||
// outColor.rgb *= ao;
|
||||
|
||||
outColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
|
||||
|
||||
gl_FragColor = vec4(outColor.rgb, outColor.a);
|
||||
|
||||
// vec4 aocol = texture(ssaotex, texCoord);
|
||||
|
|
|
@ -184,7 +184,7 @@ void main() {
|
|||
// col.rgb = tonemapFilmic(col.rgb); // With gamma
|
||||
|
||||
// To gamma
|
||||
col = vec4(pow(col.rgb, vec3(1.0 / 2.2)), col.a);
|
||||
// col = vec4(pow(col.rgb, vec3(1.0 / 2.2)), col.a);
|
||||
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
|
|
@ -11,21 +11,18 @@ uniform sampler2D gbuffer2;
|
|||
uniform mat4 P;
|
||||
uniform mat4 V;
|
||||
uniform mat4 tiV;
|
||||
uniform vec3 eye;
|
||||
|
||||
const int maxSteps = 20;
|
||||
const int numBinarySearchSteps = 5;
|
||||
|
||||
const float rayStep = 0.25;
|
||||
const float minRayStep = 0.1;
|
||||
const float searchDist = 5;
|
||||
const float rayStep = 0.04;
|
||||
const float minRayStep = 0.05;
|
||||
const float searchDist = 4.4;
|
||||
const float falloffExp = 3.0;
|
||||
// uniform float rayStep;
|
||||
// uniform float minRayStep;
|
||||
// uniform float searchDist;
|
||||
|
||||
const float falloffExp = 3.0;
|
||||
const float zNear = 1.0;
|
||||
const float zFar = 100.0;
|
||||
// uniform float falloffExp;
|
||||
|
||||
in vec2 texCoord;
|
||||
|
||||
|
@ -44,37 +41,33 @@ vec4 getProjectedCoord(vec3 hitCoord) {
|
|||
}
|
||||
|
||||
float getDeltaDepth(vec3 hitCoord) {
|
||||
// depth = texture(gbuffer0, getProjectedCoord(hitCoord).xy).a;
|
||||
// depth = (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
|
||||
// depth *= zFar;
|
||||
vec4 viewPos = vec4(texture(gbuffer1, getProjectedCoord(hitCoord).xy).rgb, 1.0);
|
||||
viewPos = V * viewPos;
|
||||
float depth = viewPos.z;
|
||||
|
||||
return hitCoord.z - depth;
|
||||
return depth - hitCoord.z;
|
||||
}
|
||||
|
||||
vec3 binarySearch(vec3 dir) {
|
||||
// for (int i = 0; i < numBinarySearchSteps; i++) {
|
||||
dir *= 0.5;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) hitCoord -= dir;
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
|
||||
|
||||
dir *= 0.5;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) hitCoord -= dir;
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
|
||||
|
||||
dir *= 0.5;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) hitCoord -= dir;
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
|
||||
|
||||
dir *= 0.5;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) hitCoord -= dir;
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
|
||||
|
||||
dir *= 0.5;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) hitCoord -= dir;
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
|
||||
// }
|
||||
return vec3(getProjectedCoord(hitCoord).xy, depth);
|
||||
}
|
||||
|
@ -83,65 +76,87 @@ vec4 rayCast(vec3 dir) {
|
|||
dir *= rayStep;
|
||||
|
||||
// for (int i = 0; i < maxSteps; i++) {
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
hitCoord -= dir;
|
||||
if (getDeltaDepth(hitCoord) < 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
|
||||
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
|
||||
// }
|
||||
return vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
@ -150,24 +165,23 @@ void main() {
|
|||
float roughness = texture(gbuffer1, texCoord).a;
|
||||
float reflectivity = 1.0 - roughness;
|
||||
if (reflectivity == 0.0) {
|
||||
vec4 texColor = texture(tex, texCoord);
|
||||
gl_FragColor = texColor;
|
||||
return;
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 viewNormal = vec4(texture(gbuffer0, texCoord).rgb, 1.0);
|
||||
viewNormal = tiV * viewNormal;
|
||||
// viewNormal /= viewNormal.w;
|
||||
if (viewNormal.z <= 0.9) discard; // Only up facing surfaces for now
|
||||
viewNormal = tiV * normalize(viewNormal);
|
||||
|
||||
vec4 viewPos = vec4(texture(gbuffer1, texCoord).rgb, 1.0);
|
||||
viewPos = V * viewPos;
|
||||
//viewPos /= viewPos.w;
|
||||
|
||||
vec3 reflected = normalize(reflect(normalize(viewPos.xyz), normalize(viewNormal.xyz)));
|
||||
vec3 reflected = normalize(reflect((viewPos.xyz), normalize(viewNormal.xyz)));
|
||||
hitCoord = viewPos.xyz;
|
||||
|
||||
vec3 dir = reflected * max(minRayStep, -viewPos.z);// * (1.0 - rand(texCoord) * 0.7);
|
||||
vec3 dir = reflected * max(minRayStep, -viewPos.z);// * (1.0 - rand(texCoord) * 0.5);
|
||||
vec4 coords = rayCast(dir);
|
||||
|
||||
// TODO: prevent sampling coords from envmap
|
||||
|
||||
vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
|
||||
float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);
|
||||
|
|
Loading…
Reference in a new issue