Somewhat working camera
This commit is contained in:
@@ -28,10 +28,10 @@ void computeFrustums(ComputeShaderInput in)
|
||||
|
||||
float4 screenSpace[4];
|
||||
|
||||
screenSpace[0] = float4(in.dispatchThreadID.xy * BLOCK_SIZE, 1.0f, 1.0f);
|
||||
screenSpace[1] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y) * BLOCK_SIZE, 1.0f, 1.0f);
|
||||
screenSpace[2] = float4(float2(in.dispatchThreadID.x, in.dispatchThreadID.y + 1) * BLOCK_SIZE, 1.0f, 1.0f);
|
||||
screenSpace[3] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, 1.0f, 1.0f);
|
||||
screenSpace[0] = float4(in.dispatchThreadID.xy * BLOCK_SIZE, -1.0f, 1.0f);
|
||||
screenSpace[1] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y) * BLOCK_SIZE, -1.0f, 1.0f);
|
||||
screenSpace[2] = float4(float2(in.dispatchThreadID.x, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f);
|
||||
screenSpace[3] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f);
|
||||
|
||||
//Convert to viewSpace
|
||||
float3 viewSpace[4];
|
||||
@@ -44,10 +44,10 @@ void computeFrustums(ComputeShaderInput in)
|
||||
//Compute frustum
|
||||
Frustum frustum;
|
||||
|
||||
frustum.planes[0] = computePlane(eyePos, viewSpace[0], viewSpace[2]);
|
||||
frustum.planes[1] = computePlane(eyePos, viewSpace[3], viewSpace[1]);
|
||||
frustum.planes[2] = computePlane(eyePos, viewSpace[1], viewSpace[0]);
|
||||
frustum.planes[3] = computePlane(eyePos, viewSpace[2], viewSpace[3]);
|
||||
frustum.planes[0] = computePlane(eyePos, viewSpace[2], viewSpace[0]);
|
||||
frustum.planes[1] = computePlane(eyePos, viewSpace[1], viewSpace[3]);
|
||||
frustum.planes[2] = computePlane(eyePos, viewSpace[0], viewSpace[1]);
|
||||
frustum.planes[3] = computePlane(eyePos, viewSpace[3], viewSpace[2]);
|
||||
|
||||
if(in.dispatchThreadID.x < numThreads.x && in.dispatchThreadID.y < numThreads.y)
|
||||
{
|
||||
|
||||
@@ -32,9 +32,9 @@ VertexStageOutput vertexMain(
|
||||
float4 clipSpacePosition;
|
||||
|
||||
float3x3 tangentToLocal = cache.getTangentToLocal();
|
||||
MaterialVertexParameter vertexParams = input.getMaterialVertexParameters(cache, worldPosition, tangentToLocal);
|
||||
|
||||
float4 viewSpacePosition = mul(gViewParams.viewMatrix, float4(worldPosition, 1));
|
||||
MaterialVertexParameter vertexParams = input.getMaterialVertexParameters(cache, worldPosition, viewSpacePosition.xyz, tangentToLocal);
|
||||
|
||||
clipSpacePosition = mul(gViewParams.projectionMatrix, viewSpacePosition);
|
||||
output.position = clipSpacePosition;
|
||||
output.shaderAttributeInterpolation = input.getInterpolants(cache, vertexParams);
|
||||
@@ -66,12 +66,13 @@ float4 fragmentMain(
|
||||
uint startOffset = gridValue.x;
|
||||
uint lightCount = gridValue.y;
|
||||
|
||||
for (int j = 0; j < lightCount; ++j)
|
||||
for (int j = 0; j < numPointLights; ++j)
|
||||
{
|
||||
uint lightIndex = lightIndexList[startOffset + j];
|
||||
PointLight pointLight = pointLights[lightIndex];
|
||||
//uint lightIndex = lightIndexList[startOffset + j];
|
||||
PointLight pointLight = pointLights[j];
|
||||
if(pointLight.colorRange.w < length(pointLight.getViewPos() - input.viewPosition)) continue;
|
||||
result += pointLight.illuminate(materialParams, brdf, viewDir);
|
||||
}
|
||||
return float4(result, 0.1f);
|
||||
return float4(result, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,18 +4,18 @@ import Common;
|
||||
|
||||
interface ILightEnv
|
||||
{
|
||||
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 wo);
|
||||
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 wo);
|
||||
};
|
||||
|
||||
struct DirectionalLight : ILightEnv
|
||||
{
|
||||
float4 color;
|
||||
float4 direction;
|
||||
float4 intensity;
|
||||
float4 color;
|
||||
float4 direction;
|
||||
float4 intensity;
|
||||
|
||||
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 wo)
|
||||
{
|
||||
return intensity.xyz * brdf.evaluate(wo, normalize(direction.xyz), input.worldNormal, input.worldTangent, input.worldBiTangent, color.xyz);
|
||||
{
|
||||
return intensity.xyz * brdf.evaluate(wo, normalize(direction.xyz), input.worldNormal, input.worldTangent, input.worldBiTangent, color.xyz);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,40 +25,40 @@ struct PointLight : ILightEnv
|
||||
float4 colorRange;
|
||||
|
||||
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 viewDir)
|
||||
{
|
||||
{
|
||||
float3 lightVec = positionWS.xyz - input.worldPosition;
|
||||
float d = length(lightVec);
|
||||
float3 direction = normalize(lightVec);
|
||||
float illuminance = max(1 - d / colorRange.w, 0);
|
||||
return illuminance * brdf.evaluate(viewDir, direction, input.worldNormal, input.worldTangent, input.worldBiTangent, colorRange.xyz);
|
||||
return illuminance * brdf.evaluate(viewDir, direction, input.worldNormal, input.worldTangent, input.worldBiTangent, colorRange.xyz);
|
||||
}
|
||||
|
||||
bool insidePlane(Plane plane)
|
||||
{
|
||||
bool insidePlane(Plane plane)
|
||||
{
|
||||
return dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w;
|
||||
}
|
||||
}
|
||||
|
||||
bool insideFrustum(Frustum frustum, float zNear, float zFar)
|
||||
{
|
||||
bool insideFrustum(Frustum frustum, float zNear, float zFar)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
for(int i = 0; i < 4 && result; ++i)
|
||||
{
|
||||
if(insidePlane(frustum.planes[i]))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
float3 getViewPos()
|
||||
{
|
||||
return mul(gViewParams.viewMatrix, positionWS).xyz;
|
||||
}
|
||||
if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
|
||||
{
|
||||
//result = false;
|
||||
}
|
||||
for(int i = 0; i < 4 && result; ++i)
|
||||
{
|
||||
if(insidePlane(frustum.planes[i]))
|
||||
{
|
||||
//result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
float3 getViewPos()
|
||||
{
|
||||
return mul(gViewParams.viewMatrix, positionWS).xyz;
|
||||
}
|
||||
};
|
||||
|
||||
layout(set = INDEX_LIGHT_ENV, binding = 0, std430)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
struct MaterialVertexParameter
|
||||
{
|
||||
float3 worldPosition;
|
||||
float3 viewPosition;
|
||||
float3x3 tangentToWorld;
|
||||
#if NUM_MATERIAL_TEXCOORDS
|
||||
float2 texCoords[NUM_MATERIAL_TEXCOORDS];
|
||||
|
||||
@@ -45,6 +45,7 @@ struct VertexValueCache
|
||||
struct ShaderAttributeInterpolation
|
||||
{
|
||||
float3 worldPosition;
|
||||
float3 viewPosition;
|
||||
float3 normal;
|
||||
float3 tangent;
|
||||
float3 biTangent;
|
||||
@@ -158,10 +159,11 @@ struct VertexShaderInput
|
||||
return cache;
|
||||
}
|
||||
|
||||
MaterialVertexParameter getMaterialVertexParameters(VertexValueCache cache, float3 worldPosition, float3x3 tangentToLocal)
|
||||
MaterialVertexParameter getMaterialVertexParameters(VertexValueCache cache, float3 worldPosition, float3 viewPosition, float3x3 tangentToLocal)
|
||||
{
|
||||
MaterialVertexParameter result;
|
||||
result.worldPosition = worldPosition;
|
||||
result.viewPosition = viewPosition;
|
||||
result.vertexColor = cache.color;
|
||||
result.tangentToWorld = cache.getTangentToWorld();
|
||||
// TODO instancing
|
||||
@@ -186,6 +188,7 @@ struct VertexShaderInput
|
||||
result.biTangent = mul(gSceneData.localToWorld, float4(biTangent, 0.0f)).xyz;
|
||||
result.color = color;
|
||||
result.worldPosition = vertexParams.worldPosition;
|
||||
result.viewPosition = vertexParams.viewPosition;
|
||||
for(int i = 0; i < NUM_MATERIAL_TEXCOORDS; ++i)
|
||||
{
|
||||
if(i % 2)
|
||||
|
||||
Reference in New Issue
Block a user