Trying to add opacity
This commit is contained in:
@@ -34,6 +34,6 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
// gamma correction
|
// gamma correction
|
||||||
result = result / (result + float3(1.0));
|
result = result / (result + float3(1.0));
|
||||||
result = pow(result, float3(1.0/2.2));
|
result = pow(result, float3(1.0/2.2));
|
||||||
return float4(result, 1.0f);
|
return float4(result, brdf.getAlpha());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4,11 +4,13 @@ interface IBRDF
|
|||||||
{
|
{
|
||||||
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor);
|
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor);
|
||||||
float3 evaluateAmbient();
|
float3 evaluateAmbient();
|
||||||
|
float getAlpha();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Phong : IBRDF
|
struct Phong : IBRDF
|
||||||
{
|
{
|
||||||
float3 baseColor;
|
float3 baseColor;
|
||||||
|
float alpha;
|
||||||
float3 specular;
|
float3 specular;
|
||||||
float3 normal;
|
float3 normal;
|
||||||
float3 ambient;
|
float3 ambient;
|
||||||
@@ -16,6 +18,7 @@ struct Phong : IBRDF
|
|||||||
|
|
||||||
__init()
|
__init()
|
||||||
{
|
{
|
||||||
|
alpha = 1;
|
||||||
normal = float3(0, 0, 1);
|
normal = float3(0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,11 +36,16 @@ struct Phong : IBRDF
|
|||||||
{
|
{
|
||||||
return ambient;
|
return ambient;
|
||||||
}
|
}
|
||||||
|
float getAlpha()
|
||||||
|
{
|
||||||
|
return alpha;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BlinnPhong : IBRDF
|
struct BlinnPhong : IBRDF
|
||||||
{
|
{
|
||||||
float3 baseColor;
|
float3 baseColor;
|
||||||
|
float alpha;
|
||||||
float3 specularColor;
|
float3 specularColor;
|
||||||
float3 normal;
|
float3 normal;
|
||||||
float shininess;
|
float shininess;
|
||||||
@@ -45,6 +53,7 @@ struct BlinnPhong : IBRDF
|
|||||||
|
|
||||||
__init()
|
__init()
|
||||||
{
|
{
|
||||||
|
alpha = 1;
|
||||||
normal = float3(0, 0, 1);
|
normal = float3(0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,15 +71,21 @@ struct BlinnPhong : IBRDF
|
|||||||
{
|
{
|
||||||
return ambient;
|
return ambient;
|
||||||
}
|
}
|
||||||
|
float getAlpha()
|
||||||
|
{
|
||||||
|
return alpha;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CelShading : IBRDF
|
struct CelShading : IBRDF
|
||||||
{
|
{
|
||||||
float3 baseColor;
|
float3 baseColor;
|
||||||
|
float alpha;
|
||||||
float3 normal;
|
float3 normal;
|
||||||
|
|
||||||
__init()
|
__init()
|
||||||
{
|
{
|
||||||
|
alpha = 1;
|
||||||
normal = float3(0, 0, 1);
|
normal = float3(0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,12 +109,17 @@ struct CelShading : IBRDF
|
|||||||
{
|
{
|
||||||
return float3(0, 0, 0);
|
return float3(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
float getAlpha()
|
||||||
|
{
|
||||||
|
return alpha;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://learnopengl.com/PBR/Theory
|
// https://learnopengl.com/PBR/Theory
|
||||||
struct CookTorrance : IBRDF
|
struct CookTorrance : IBRDF
|
||||||
{
|
{
|
||||||
float3 baseColor;
|
float3 baseColor;
|
||||||
|
float alpha;
|
||||||
float3 normal;
|
float3 normal;
|
||||||
float roughness;
|
float roughness;
|
||||||
float metallic;
|
float metallic;
|
||||||
@@ -107,6 +127,7 @@ struct CookTorrance : IBRDF
|
|||||||
|
|
||||||
__init()
|
__init()
|
||||||
{
|
{
|
||||||
|
alpha = 1;
|
||||||
normal = float3(0, 0, 1);
|
normal = float3(0, 0, 1);
|
||||||
roughness = 0;
|
roughness = 0;
|
||||||
metallic = 0;
|
metallic = 0;
|
||||||
@@ -176,4 +197,8 @@ struct CookTorrance : IBRDF
|
|||||||
{
|
{
|
||||||
return float3(0.03) * baseColor * ambientOcclusion;
|
return float3(0.03) * baseColor * ambientOcclusion;
|
||||||
}
|
}
|
||||||
|
float getAlpha()
|
||||||
|
{
|
||||||
|
return alpha;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,5 +53,7 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
|||||||
// gamma correction
|
// gamma correction
|
||||||
result = result / (result + float3(1.0));
|
result = result / (result + float3(1.0));
|
||||||
result = pow(result, float3(1.0/2.2));
|
result = pow(result, float3(1.0/2.2));
|
||||||
|
|
||||||
|
|
||||||
hitValue.color = result;
|
hitValue.color = result;
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ void raygen()
|
|||||||
rayDesc.TMax = 10000.0;
|
rayDesc.TMax = 10000.0;
|
||||||
|
|
||||||
RayPayload payload;
|
RayPayload payload;
|
||||||
|
payload.rayDirection = rayDesc.Direction;
|
||||||
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload);
|
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload);
|
||||||
|
|
||||||
pRayTracingParams.image[int2(LaunchID.xy)] = float4(payload.color, 1.0);
|
pRayTracingParams.image[int2(LaunchID.xy)] = float4(payload.color, 1.0);
|
||||||
|
|||||||
@@ -17,5 +17,6 @@ struct CallablePayload
|
|||||||
|
|
||||||
struct RayPayload
|
struct RayPayload
|
||||||
{
|
{
|
||||||
|
float3 rayDirection;
|
||||||
float3 color;
|
float3 color;
|
||||||
};
|
};
|
||||||
@@ -80,6 +80,7 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr const char* KEY_BASE_COLOR = "k_b";
|
||||||
constexpr const char* KEY_DIFFUSE_COLOR = "k_d";
|
constexpr const char* KEY_DIFFUSE_COLOR = "k_d";
|
||||||
constexpr const char* KEY_SPECULAR_COLOR = "k_s";
|
constexpr const char* KEY_SPECULAR_COLOR = "k_s";
|
||||||
constexpr const char* KEY_AMBIENT_COLOR = "k_a";
|
constexpr const char* KEY_AMBIENT_COLOR = "k_a";
|
||||||
@@ -270,15 +271,24 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
|||||||
|
|
||||||
result = blendKey;
|
result = blendKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
addVectorParameter(KEY_DIFFUSE_COLOR, AI_MATKEY_COLOR_DIFFUSE);
|
addVectorParameter(KEY_DIFFUSE_COLOR, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
std::string outputDiffuse = KEY_DIFFUSE_COLOR;
|
std::string outputBase = KEY_BASE_COLOR;
|
||||||
uint32 numDiffuseTextures = material->GetTextureCount(aiTextureType_DIFFUSE);
|
uint32 numDiffuseTextures = material->GetTextureCount(aiTextureType_DIFFUSE);
|
||||||
for (uint32 i = 0; i < numDiffuseTextures; ++i) {
|
for (uint32 i = 0; i < numDiffuseTextures; ++i) {
|
||||||
addTextureParameter(KEY_DIFFUSE_TEXTURE, aiTextureType_DIFFUSE, i, outputDiffuse);
|
addTextureParameter(KEY_DIFFUSE_TEXTURE, aiTextureType_DIFFUSE, i, outputBase, {0, 1, 2, 3});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string outputDiffuse = KEY_DIFFUSE_COLOR;
|
||||||
|
expressions.add(new SwizzleExpression({0, 1, 2, -1}));
|
||||||
|
expressions.back()->key = outputDiffuse;
|
||||||
|
expressions.back()->inputs["target"].source = outputBase;
|
||||||
|
|
||||||
|
std::string outputAlpha = "alpha";
|
||||||
|
expressions.add(new SwizzleExpression({-1, -1, -1, 0}));
|
||||||
|
expressions.back()->key = outputDiffuse;
|
||||||
|
expressions.back()->inputs["target"].source = outputBase;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
addVectorParameter(KEY_SPECULAR_COLOR, AI_MATKEY_COLOR_SPECULAR);
|
addVectorParameter(KEY_SPECULAR_COLOR, AI_MATKEY_COLOR_SPECULAR);
|
||||||
std::string outputSpecular = KEY_SPECULAR_COLOR;
|
std::string outputSpecular = KEY_SPECULAR_COLOR;
|
||||||
@@ -335,6 +345,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
|||||||
|
|
||||||
MaterialNode brdf;
|
MaterialNode brdf;
|
||||||
brdf.variables["baseColor"] = outputDiffuse;
|
brdf.variables["baseColor"] = outputDiffuse;
|
||||||
|
brdf.variables["alpha"] = outputAlpha;
|
||||||
if (!outputNormal.empty()) {
|
if (!outputNormal.empty()) {
|
||||||
expressions.add(new MulExpression());
|
expressions.add(new MulExpression());
|
||||||
expressions.back()->key = "NormalMul";
|
expressions.back()->key = "NormalMul";
|
||||||
@@ -376,15 +387,8 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
bool twoSided = true;
|
|
||||||
material->Get(AI_MATKEY_TWOSIDED, twoSided);
|
|
||||||
float opacity = 1.0f;
|
|
||||||
if (std::strcmp(material->GetName().C_Str(), "3td_Africa_Grass01") == 0)
|
|
||||||
{
|
|
||||||
opacity = 0.5f;
|
|
||||||
}
|
|
||||||
OMaterialAsset baseMat = new MaterialAsset(importPath, materialName);
|
OMaterialAsset baseMat = new MaterialAsset(importPath, materialName);
|
||||||
baseMat->material = new Material(graphics, numTextures, numSamplers, numFloats, twoSided, opacity, materialName,
|
baseMat->material = new Material(graphics, numTextures, numSamplers, numFloats, 1, 1, materialName,
|
||||||
std::move(expressions), std::move(parameters), std::move(brdf));
|
std::move(expressions), std::move(parameters), std::move(brdf));
|
||||||
baseMat->material->compile();
|
baseMat->material->compile();
|
||||||
graphics->getShaderCompiler()->registerMaterial(baseMat->material);
|
graphics->getShaderCompiler()->registerMaterial(baseMat->material);
|
||||||
|
|||||||
@@ -602,7 +602,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
|||||||
.pStages = shaderStages.data(),
|
.pStages = shaderStages.data(),
|
||||||
.groupCount = static_cast<uint32>(shaderGroups.size()),
|
.groupCount = static_cast<uint32>(shaderGroups.size()),
|
||||||
.pGroups = shaderGroups.data(),
|
.pGroups = shaderGroups.data(),
|
||||||
.maxPipelineRayRecursionDepth = 1,
|
.maxPipelineRayRecursionDepth = 12,
|
||||||
.layout = createInfo.pipelineLayout.cast<PipelineLayout>()->getHandle(),
|
.layout = createInfo.pipelineLayout.cast<PipelineLayout>()->getHandle(),
|
||||||
};
|
};
|
||||||
VkPipeline pipelineHandle;
|
VkPipeline pipelineHandle;
|
||||||
|
|||||||
Reference in New Issue
Block a user