projection work + tests

This commit is contained in:
Nick Fisher
2025-03-28 10:01:00 +08:00
parent e8169e86d1
commit cd1c2f3827
8 changed files with 687 additions and 39 deletions

View File

@@ -100,8 +100,8 @@ fragment {
//material.baseColor = vec4(sampledDepth.r, 0.0, 0.0, 1.0);
//material.baseColor = vec4(vertexDepth, 0.0, 0.0, 1.0);
if(materialParams.useDepth && abs(vertexDepth - sampledDepth.r) > 0.001) {
discard;
if(materialParams.useDepth && (sampledDepth.r < 0.0001 || abs(vertexDepth - sampledDepth.r) > 0.001)) {
material.baseColor = vec4(0.0, 0.0, 0.0, 0.0);
} else {
vec2 texSize = vec2(textureSize(materialParams_color, 0));
vec4 color = textureLod(materialParams_color, uvToRenderTargetUV(deviceCoords.xy), 0.0f);

View File

@@ -8,7 +8,7 @@ material {
},
{
type : float3[3],
name : cameraPositions
name : cameraForwardVectors
},
{
type : bool,
@@ -17,8 +17,8 @@ material {
],
variables : [
{
type : float3,
name : blendWeights,
type : float,
name : samplerCoord,
}
],
requires : [ position, uv0 ],
@@ -43,42 +43,57 @@ material {
// Parameters:
// - perspectives: 3D texture containing different perspective views of the object
// - cameraPositions: Array of camera positions used to render each perspective slice
vertex {
void materialVertex(inout MaterialVertexInputs material) {
vec3 worldCameraPos = getWorldCameraPosition();
vec4 currentCameraPos = getUserWorldFromWorldMatrix() * vec4(worldCameraPos, 1.0);
vec3 forward = -(normalize(getWorldFromViewMatrix()[2].xyz));
vec3 weights = vec3(0.0, 0.0, 0.0);
int idxMax = 0;
float weightMax = 0.0;
for(int i = 0; i < 3; i++) {
weights[i] = dot(forward, materialParams.cameraForwardVectors[i]);
if(weights[i] > weightMax) {
weightMax = weights[i];
idxMax = i;
}
}
if(idxMax == 0) {
float z = (weights.y * 0.5) + (weights.z * 1.0);
}
//weights /= (weights.x + weights.y + weights.z);
material.blendWeights.xyz = vec3(0.0f);
float totalWeight = 0.0;
for (int i = 0; i < 3; i++) {
vec3 cameraPos = materialParams.cameraPositions[i];
float dist = distance(currentCameraPos.xyz, cameraPos);
material.blendWeights[i] = exp(-dist);
totalWeight += material.blendWeights[i];
}
if (totalWeight > 0.0) {
material.blendWeights /= totalWeight;
}
//material.blendWeights.x = exp(-distance(currentCameraPos.xyz, materialParams.cameraPositions[0]));
material.samplerCoord.x = z;
}
}
fragment {
void useMax(vec3 forward) {
float maxIdx = 0.0f;
float maxWeight = 0.0f;
for(int i =0; i < 3; i++) {
float weight = dot(forward, materialParams.cameraForwardVectors[i]);
if(weight > maxWeight) {
maxWeight = weight;
maxIdx = float(i) / 2.0f;
}
}
float z = maxIdx;
}
void material(inout MaterialInputs material) {
prepareMaterial(material);
vec3 weights = variable_blendWeights.xyz;
float z = (weights.x * 0.0) + (weights.y * 0.5) + (weights.z * 1.0);
vec2 uv = getUV0();
if(materialParams.flipUVs) {
uv = uvToRenderTargetUV(uv);
}
vec3 texCoord = vec3(uv, z);
vec3 texCoord = vec3(uv, variable_samplerCoord.x);
material.baseColor = texture(materialParams_perspectives, texCoord);
}
}