Somewhat working camera
This commit is contained in:
@@ -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