adding anyhit, doesnt work though
This commit is contained in:
@@ -32,7 +32,5 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
}
|
||||
result += brdf.evaluateAmbient();
|
||||
// gamma correction
|
||||
//result = result / (result + float3(1.0));
|
||||
//result = pow(result, float3(1.0/2.2));
|
||||
return float4(result, brdf.getAlpha());
|
||||
}
|
||||
+73
-21
@@ -2,10 +2,13 @@ import Common;
|
||||
|
||||
interface IBRDF
|
||||
{
|
||||
float3 evaluate(float3x3 tangentToWorld, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
|
||||
[mutating] void transformNormal(float3x3 tangentToWorld);
|
||||
float3 getNormal();
|
||||
float3 getBaseColor();
|
||||
float3 evaluateAmbient();
|
||||
float getAlpha();
|
||||
float3 getTangentNormal();
|
||||
float3 getEmissive();
|
||||
};
|
||||
|
||||
struct Phong : IBRDF
|
||||
@@ -29,16 +32,28 @@ struct Phong : IBRDF
|
||||
emissive = float3(0, 0, 0);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tangentToWorld, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
{
|
||||
float3 normal_WS = normalize(mul(tangentToWorld, normal));
|
||||
float3 normal_WS = normal;
|
||||
float3 nDotL = dot(normal_WS, lightDir_WS);
|
||||
float3 r = 2 * (nDotL) * normal_WS - lightDir_WS;
|
||||
float rDotV = dot(r, viewDir_WS);
|
||||
|
||||
return lightColor * (baseColor * max(nDotL, 0.0)) + specular * pow(max(rDotV, 0.0), max(shininess, 1));
|
||||
}
|
||||
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
float3 getBaseColor()
|
||||
{
|
||||
return baseColor;
|
||||
}
|
||||
float3 evaluateAmbient()
|
||||
{
|
||||
return ambient;
|
||||
@@ -47,9 +62,9 @@ struct Phong : IBRDF
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
float3 getTangentNormal()
|
||||
float3 getEmissive()
|
||||
{
|
||||
return normal;
|
||||
return emissive;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,16 +89,28 @@ struct BlinnPhong : IBRDF
|
||||
emissive = float3(0, 0, 0);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tangentToWorld, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
{
|
||||
float3 normal_WS = normalize(mul(tangentToWorld, normal));
|
||||
float3 normal_WS = normal;
|
||||
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
||||
float3 h = normalize(lightDir_WS + viewDir_WS);
|
||||
float specular = pow(saturate(dot(normal_WS, h)), shininess);
|
||||
|
||||
return (baseColor * diffuse * lightColor) + (specularColor * specular);
|
||||
}
|
||||
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
float3 getBaseColor()
|
||||
{
|
||||
return baseColor;
|
||||
}
|
||||
float3 evaluateAmbient()
|
||||
{
|
||||
return ambient;
|
||||
@@ -92,9 +119,9 @@ struct BlinnPhong : IBRDF
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
float3 getTangentNormal()
|
||||
float3 getEmissive()
|
||||
{
|
||||
return normal;
|
||||
return emissive;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -112,10 +139,9 @@ struct CelShading : IBRDF
|
||||
normal = float3(0, 0, 1);
|
||||
emissive = float3(0, 0, 0);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tangentToWorld, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
{
|
||||
float3 normal_WS = normalize(mul(tangentToWorld, normal));
|
||||
float3 normal_WS = normal;
|
||||
float nDotL = dot(normal_WS, lightDir_WS);
|
||||
float diffuse = max(nDotL, 0);
|
||||
|
||||
@@ -129,6 +155,19 @@ struct CelShading : IBRDF
|
||||
return darkenedBase * lightColor;
|
||||
}
|
||||
}
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
float3 getBaseColor()
|
||||
{
|
||||
return baseColor;
|
||||
}
|
||||
float3 evaluateAmbient()
|
||||
{
|
||||
return float3(0, 0, 0);
|
||||
@@ -137,9 +176,9 @@ struct CelShading : IBRDF
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
float3 getTangentNormal()
|
||||
float3 getEmissive()
|
||||
{
|
||||
return normal;
|
||||
return emissive;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -197,9 +236,9 @@ struct CookTorrance : IBRDF
|
||||
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tangentToWorld, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
{
|
||||
float3 n = normalize(mul(tangentToWorld, normal));
|
||||
float3 n = normal;
|
||||
float3 h = normalize(lightDir_WS + viewDir_WS);
|
||||
|
||||
float3 F0 = float3(0.04);
|
||||
@@ -224,6 +263,19 @@ struct CookTorrance : IBRDF
|
||||
float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor;
|
||||
return result * ambientOcclusion;
|
||||
}
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
float3 getBaseColor()
|
||||
{
|
||||
return baseColor;
|
||||
}
|
||||
float3 evaluateAmbient()
|
||||
{
|
||||
return float3(0.03) * baseColor * ambientOcclusion;
|
||||
@@ -232,8 +284,8 @@ struct CookTorrance : IBRDF
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
float3 getTangentNormal()
|
||||
float3 getEmissive()
|
||||
{
|
||||
return normal;
|
||||
return emissive;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ struct DirectionalLight : ILightEnv
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
float3 dir_WS = -normalize(direction.xyz);
|
||||
return brdf.evaluate(params.tangentToWorld, params.viewDir_WS, dir_WS, color.xyz);
|
||||
return brdf.evaluate(params.viewDir_WS, dir_WS, color.xyz);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@ struct PointLight : ILightEnv
|
||||
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
||||
float d = length(lightDir_WS);
|
||||
float illuminance = max(1 - d / colorRange.w, 0);
|
||||
return illuminance * brdf.evaluate(params.tangentToWorld, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
|
||||
return illuminance * brdf.evaluate(params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
|
||||
}
|
||||
|
||||
bool insidePlane(Plane plane, float3 position)
|
||||
|
||||
@@ -5,8 +5,8 @@ import Scene;
|
||||
|
||||
//interface IMaterial
|
||||
//{
|
||||
// associatedtype BRDF : IBRDF;
|
||||
// BRDF prepare(MaterialParameter input);
|
||||
// associatedtype BRDF: IBRDF;
|
||||
// static BRDF prepare(MaterialParameter input);
|
||||
//};
|
||||
struct MaterialResources
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ import Common;
|
||||
|
||||
struct MaterialParameter
|
||||
{
|
||||
float3x3 tangentToWorld;
|
||||
float3 position_WS;
|
||||
float2 texCoords[MAX_TEXCOORDS];
|
||||
float3 vertexColor;
|
||||
@@ -9,7 +10,6 @@ struct MaterialParameter
|
||||
|
||||
struct LightingParameter
|
||||
{
|
||||
float3x3 tangentToWorld;
|
||||
float3 viewDir_WS;
|
||||
float3 position_WS;
|
||||
}
|
||||
@@ -72,6 +72,7 @@ struct FragmentParameter
|
||||
MaterialParameter getMaterialParameter()
|
||||
{
|
||||
MaterialParameter result;
|
||||
result.tangentToWorld = getTangentToWorld();
|
||||
result.position_WS = position_WS;
|
||||
result.texCoords[0] = texCoords0.xy;
|
||||
result.texCoords[1] = texCoords0.zw;
|
||||
@@ -88,7 +89,6 @@ struct FragmentParameter
|
||||
LightingParameter getLightingParameter()
|
||||
{
|
||||
LightingParameter result;
|
||||
result.tangentToWorld = getTangentToWorld();
|
||||
result.viewDir_WS = normalize(pViewParams.cameraPosition_WS.xyz - position_WS);
|
||||
result.position_WS = position_WS;
|
||||
return result;
|
||||
|
||||
@@ -6,7 +6,7 @@ struct VertexInput
|
||||
uint instanceId: SV_InstanceID;
|
||||
}
|
||||
|
||||
interface IVertexData
|
||||
{
|
||||
VertexAttributes getAttributes(uint index);
|
||||
};
|
||||
//interface IVertexData
|
||||
//{
|
||||
// VertexAttributes getAttributes(uint index);
|
||||
//};
|
||||
|
||||
@@ -5,7 +5,7 @@ import MaterialParameter;
|
||||
import StaticMeshVertexData;
|
||||
|
||||
[shader("anyhit")]
|
||||
void anyhit(inout RayPayload hitvalue, in BuiltInTriangleIntersectionAttributes attr)
|
||||
void anyhit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttributes attr)
|
||||
{
|
||||
const float3 barycentricCoords = float3(1.0f - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y);
|
||||
|
||||
@@ -31,4 +31,7 @@ void anyhit(inout RayPayload hitvalue, in BuiltInTriangleIntersectionAttributes
|
||||
|
||||
FragmentParameter params = FragmentParameter.interpolate(f0, f1, f2, barycentricCoords);
|
||||
|
||||
hitValue.params = params.getLightingParameter();
|
||||
hitValue.materialParams = params.getMaterialParameter();
|
||||
AcceptHitAndEndSearch();
|
||||
}
|
||||
@@ -83,6 +83,7 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
||||
// todo: replace with anyhit shader
|
||||
if(hitValue.anyHit)
|
||||
return;
|
||||
|
||||
const float3 barycentricCoords = float3(1.0f - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y);
|
||||
|
||||
InstanceData inst = pScene.instances[InstanceID()];
|
||||
@@ -107,14 +108,15 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
||||
|
||||
FragmentParameter params = FragmentParameter.interpolate(f0, f1, f2, barycentricCoords);
|
||||
|
||||
MaterialParameter materialParams = params.getMaterialParameter();
|
||||
LightingParameter lightingParams = params.getLightingParameter();
|
||||
hitValue.params = params.getLightingParameter();
|
||||
hitValue.materialParams = params.getMaterialParameter();
|
||||
LightingParameter lightingParams = hitValue.params;
|
||||
lightingParams.viewDir_WS = -WorldRayDirection();
|
||||
let brdf = Material.prepare(materialParams);
|
||||
let brdf = Material.prepare(hitValue.materialParams);
|
||||
|
||||
float3 normal_WS = normalize(mul(params.getTangentToWorld(), brdf.normal));
|
||||
float3 normal_WS = brdf.getNormal();
|
||||
float3 normalLight_WS = dot(normal_WS,WorldRayDirection())<0 ? normal_WS : -normal_WS;
|
||||
float3 intersection_WS = params.position_WS;
|
||||
float3 intersection_WS = lightingParams.position_WS;
|
||||
|
||||
hitValue.depth++;
|
||||
float3 rnd = rand01(hitValue.rndSeed);
|
||||
@@ -139,12 +141,12 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
||||
// TraceRay(scene, 0, 0xff, 0, 0, rayDesc);
|
||||
//}
|
||||
|
||||
float p = max(max(brdf.baseColor.x, brdf.baseColor.y), brdf.baseColor.z);
|
||||
float p = max(max(brdf.getBaseColor().x, brdf.getBaseColor().y), brdf.getBaseColor().z);
|
||||
if(hitValue.depth > 5) {
|
||||
if (rnd.z >= p) return;
|
||||
}
|
||||
|
||||
hitValue.light += brdf.emissive * hitValue.emissive + brdf.evaluateAmbient();
|
||||
hitValue.light += brdf.getEmissive() * hitValue.emissive + brdf.evaluateAmbient();
|
||||
//-- Ideal DIFFUSE reflection
|
||||
//if(bool(useNEE)) {
|
||||
// accrad += nextEventEstimation(accmat, r.d, params.x, params.nl, kt, false, rnd);
|
||||
@@ -211,7 +213,8 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
||||
payload.rndSeed = hitValue.rndSeed + 1;
|
||||
TraceRay(pRayTracingParams.scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, 0xff, 0, 0, 0, rayDesc, payload);
|
||||
float bias = dot(normalLight_WS, rayDesc.Direction);
|
||||
hitValue.light += brdf.evaluate(params.getTangentToWorld(), -WorldRayDirection(), rayDesc.Direction, payload.light / bias);
|
||||
hitValue.light += brdf.evaluate(-WorldRayDirection(), rayDesc.Direction, payload.light / bias);
|
||||
}
|
||||
hitValue.light /= p;
|
||||
//hitValue.light /= p;
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import MaterialParameter;
|
||||
import BRDF;
|
||||
|
||||
struct RayTracingParams
|
||||
{
|
||||
@@ -12,14 +13,10 @@ struct RayTracingParams
|
||||
layout(set=5)
|
||||
ParameterBlock<RayTracingParams> pRayTracingParams;
|
||||
|
||||
struct CallablePayload
|
||||
{
|
||||
FragmentParameter params;
|
||||
float3 color;
|
||||
};
|
||||
|
||||
struct RayPayload
|
||||
{
|
||||
LightingParameter params;
|
||||
MaterialParameter materialParams;
|
||||
float3 light;
|
||||
float emissive;
|
||||
uint depth;
|
||||
|
||||
@@ -172,7 +172,7 @@ void BasePass::render() {
|
||||
// LightEnv => provided by scene
|
||||
// Material => per material
|
||||
// LightCulling => calculated by pass
|
||||
permutation.setMaterial(materialData.material->getName());
|
||||
permutation.setMaterial(materialData.material->getName(), materialData.material->getProfile());
|
||||
Gfx::PermutationId id(permutation);
|
||||
|
||||
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
|
||||
@@ -273,7 +273,7 @@ void BasePass::render() {
|
||||
transparentCommand->setViewport(viewport);
|
||||
for (const auto& [_, t] : sortedDraws) {
|
||||
permutation.setVertexData(t.vertexData->getTypeName());
|
||||
permutation.setMaterial(t.matInst->getBaseMaterial()->getName());
|
||||
permutation.setMaterial(t.matInst->getBaseMaterial()->getName(), t.matInst->getBaseMaterial()->getProfile());
|
||||
Gfx::PermutationId id(permutation);
|
||||
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
||||
|
||||
@@ -87,7 +87,7 @@ void RayTracingPass::render() {
|
||||
PMaterial mat = matData.material;
|
||||
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("RayTracing");
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setMaterial(mat->getName(), mat->getProfile());
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(Gfx::PermutationId(permutation));
|
||||
@@ -97,6 +97,7 @@ void RayTracingPass::render() {
|
||||
for (uint32 i = 0; i < inst.instanceData.size(); ++i) {
|
||||
Gfx::RayTracingHitGroup callableGroup = {
|
||||
.closestHitShader = collection->callableShader,
|
||||
.anyHitShader = anyhit,
|
||||
};
|
||||
callableGroup.parameters.resize(sizeof(VertexData::DrawCallOffsets));
|
||||
std::memcpy(callableGroup.parameters.data(), &inst.offsets, sizeof(VertexData::DrawCallOffsets));
|
||||
@@ -111,12 +112,13 @@ void RayTracingPass::render() {
|
||||
PMaterial mat = transparentData.matInst->getBaseMaterial();
|
||||
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("RayTracing");
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setMaterial(mat->getName(), mat->getProfile());
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(Gfx::PermutationId(permutation));
|
||||
assert(collection != nullptr);
|
||||
Gfx::RayTracingHitGroup callableGroup = {
|
||||
.closestHitShader = collection->callableShader,
|
||||
.anyHitShader = anyhit,
|
||||
};
|
||||
callableGroup.parameters.resize(sizeof(VertexData::DrawCallOffsets));
|
||||
std::memcpy(callableGroup.parameters.data(), &transparentData.offsets, sizeof(VertexData::DrawCallOffsets));
|
||||
@@ -200,14 +202,15 @@ void RayTracingPass::publishOutputs() {
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
|
||||
ShaderCompilationInfo compileInfo = {
|
||||
.name = "RayGenMiss",
|
||||
.modules = {"RayGen", "Miss"},
|
||||
.entryPoints = {{"raygen", "RayGen"}, {"miss", "Miss"}},
|
||||
.modules = {"RayGen", "AnyHit", "Miss"},
|
||||
.entryPoints = {{"raygen", "RayGen"}, {"anyhit", "AnyHit"}, {"miss", "Miss"}},
|
||||
.defines = {{"RAY_TRACING", "1"}},
|
||||
.rootSignature = pipelineLayout,
|
||||
};
|
||||
graphics->beginShaderCompilation(compileInfo);
|
||||
rayGen = graphics->createRayGenShader({0});
|
||||
miss = graphics->createMissShader({1});
|
||||
anyhit = graphics->createAnyHitShader({1});
|
||||
miss = graphics->createMissShader({2});
|
||||
pipelineLayout->create();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class RayTracingPass : public RenderPass {
|
||||
Gfx::PTextureCube skyBox;
|
||||
Gfx::OSampler skyBoxSampler;
|
||||
Gfx::ORayGenShader rayGen;
|
||||
Gfx::OAnyHitShader anyhit;
|
||||
Gfx::OMissShader miss;
|
||||
Gfx::PRayTracingPipeline pipeline;
|
||||
Gfx::OTopLevelAS tlas;
|
||||
|
||||
@@ -66,7 +66,7 @@ void ShaderCompiler::compile() {
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setMaterial(mat->getName(), mat->getProfile());
|
||||
createShaders(permutation, std::move(layout), name);
|
||||
});
|
||||
}
|
||||
@@ -108,6 +108,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
|
||||
if (std::strlen(permutation.materialName) > 0) {
|
||||
createInfo.modules.add(permutation.materialName);
|
||||
createInfo.defines["MATERIAL_FILE_NAME"] = permutation.materialName;
|
||||
//createInfo.typeParameter.add({"IBRDF", "Phong"});
|
||||
}
|
||||
if (permutation.positionOnly) {
|
||||
createInfo.defines["POS_ONLY"] = "1";
|
||||
|
||||
@@ -91,6 +91,7 @@ struct ShaderPermutation {
|
||||
char vertexMeshFile[32];
|
||||
char fragmentFile[32];
|
||||
char vertexDataName[32];
|
||||
char brdfProfile[32];
|
||||
char materialName[64];
|
||||
uint8 hasFragment;
|
||||
uint8 useMeshShading;
|
||||
@@ -106,36 +107,38 @@ struct ShaderPermutation {
|
||||
void setTaskFile(std::string_view name) {
|
||||
std::memset(taskFile, 0, sizeof(taskFile));
|
||||
hasTaskShader = 1;
|
||||
strncpy(taskFile, name.data(), sizeof(taskFile));
|
||||
strncpy(taskFile, name.data(), name.size());
|
||||
}
|
||||
void setVertexFile(std::string_view name) {
|
||||
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
|
||||
useMeshShading = 0;
|
||||
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
|
||||
strncpy(vertexMeshFile, name.data(), name.size());
|
||||
}
|
||||
void setMeshFile(std::string_view name) {
|
||||
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
|
||||
useMeshShading = 1;
|
||||
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
|
||||
strncpy(vertexMeshFile, name.data(), name.size());
|
||||
}
|
||||
void setRayTracingFile(std::string_view name) {
|
||||
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
|
||||
rayTracing = true;
|
||||
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
|
||||
strncpy(vertexMeshFile, name.data(), name.size());
|
||||
}
|
||||
void setFragmentFile(std::string_view name) {
|
||||
std::memset(fragmentFile, 0, sizeof(fragmentFile));
|
||||
hasFragment = 1;
|
||||
strncpy(fragmentFile, name.data(), sizeof(fragmentFile));
|
||||
strncpy(fragmentFile, name.data(), name.size());
|
||||
}
|
||||
void setVertexData(std::string_view name) {
|
||||
std::memset(vertexDataName, 0, sizeof(vertexDataName));
|
||||
strncpy(vertexDataName, name.data(), sizeof(vertexDataName));
|
||||
strncpy(vertexDataName, name.data(), name.size());
|
||||
}
|
||||
void setMaterial(std::string_view name) {
|
||||
void setMaterial(std::string_view name, std::string_view brdf) {
|
||||
std::memset(materialName, 0, sizeof(materialName));
|
||||
std::memset(brdfProfile, 0, sizeof(brdfProfile));
|
||||
useMaterial = 1;
|
||||
strncpy(materialName, name.data(), sizeof(materialName));
|
||||
strncpy(materialName, name.data(), name.size());
|
||||
strncpy(brdfProfile, brdf.data(), brdf.size());
|
||||
}
|
||||
void setPositionOnly(bool enable) { positionOnly = enable; }
|
||||
void setDepthCulling(bool enable) { depthCulling = enable; }
|
||||
|
||||
@@ -508,6 +508,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
uint32 intersectionIndex = VK_SHADER_UNUSED_KHR;
|
||||
if (hitgroup.anyHitShader != nullptr) {
|
||||
auto anyHit = hitgroup.anyHitShader.cast<AnyHitShader>();
|
||||
anyHitIndex = shaderStages.size();
|
||||
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -520,6 +521,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
}
|
||||
if (hitgroup.intersectionShader != nullptr) {
|
||||
auto intersect = hitgroup.intersectionShader.cast<IntersectionShader>();
|
||||
intersectionIndex = shaderGroups.size();
|
||||
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
|
||||
@@ -18,6 +18,7 @@ using namespace Seele;
|
||||
{ \
|
||||
if (diagnostics) { \
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; \
|
||||
abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
sessionDesc.preprocessorMacroCount = macros.size();
|
||||
sessionDesc.preprocessorMacros = macros.data();
|
||||
slang::TargetDesc targetDesc;
|
||||
targetDesc.profile = globalSession->findProfile("glsl_450");
|
||||
targetDesc.profile = globalSession->findProfile("spv_1_4");
|
||||
targetDesc.format = target;
|
||||
sessionDesc.targetCount = 1;
|
||||
sessionDesc.targets = &targetDesc;
|
||||
@@ -149,10 +150,10 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
if (info.name == "RayGenMiss")
|
||||
{
|
||||
layout->addMapping("pVertexData", 1);
|
||||
layout->addMapping("pResources", 4);
|
||||
layout->addMapping("pLightEnv", 3);
|
||||
layout->addMapping("pRayTracingParams", 5);
|
||||
layout->addMapping("pScene", 2);
|
||||
layout->addMapping("pLightEnv", 3);
|
||||
layout->addMapping("pResources", 4);
|
||||
layout->addMapping("pRayTracingParams", 5);
|
||||
}
|
||||
// layout->addMapping("pWaterMaterial", 1);
|
||||
}
|
||||
|
||||
@@ -172,6 +172,7 @@ void Material::compile() {
|
||||
for (const auto& [name, exp] : brdf.variables) {
|
||||
codeStream << "\t\tresult." << name << " = " << varState[exp] << ";" << std::endl;
|
||||
}
|
||||
codeStream << "\t\tresult.transformNormal(input.tangentToWorld);" << std::endl;
|
||||
codeStream << "\t\treturn result;\n";
|
||||
codeStream << "\t}\n";
|
||||
codeStream << "};\n";
|
||||
|
||||
@@ -27,6 +27,7 @@ class Material {
|
||||
|
||||
OMaterialInstance instantiate();
|
||||
const std::string& getName() const { return materialName; }
|
||||
const std::string& getProfile() const { return brdf.profile; }
|
||||
|
||||
bool isTwoSided() const;
|
||||
bool hasTransparency() const;
|
||||
|
||||
Reference in New Issue
Block a user