diff --git a/Source/Engine/ShadersCompilation/ShadersCompilation.cpp b/Source/Engine/ShadersCompilation/ShadersCompilation.cpp index ce4116134..b8d51b7b5 100644 --- a/Source/Engine/ShadersCompilation/ShadersCompilation.cpp +++ b/Source/Engine/ShadersCompilation/ShadersCompilation.cpp @@ -143,9 +143,20 @@ bool ShadersCompilation::Compile(ShaderCompilationOptions& options) #endif } - // Print info if succeed - if (result == false) + if (result) { + // Output shader source to easily investigate errors (eg. for generated shaders like materials or particles) + const String outputSourceFolder = Globals::ProjectCacheFolder / TEXT("/Shaders/Source"); + const String outputSourcePath = outputSourceFolder / options.TargetName + TEXT(".hlsl"); + if (!FileSystem::DirectoryExists(outputSourceFolder)) + FileSystem::CreateDirectory(outputSourceFolder); + File::WriteAllBytes(outputSourcePath, (const byte*)options.Source, options.SourceLength); + LOG(Error, "Shader compilation '{0}' failed (profile: {1})", options.TargetName, ::ToString(options.Profile)); + LOG(Error, "Source: {0}", outputSourcePath); + } + else + { + // Success const DateTime endTime = DateTime::NowUTC(); LOG(Info, "Shader compilation '{0}' succeed in {1} ms (profile: {2})", options.TargetName, Math::CeilToInt(static_cast((endTime - startTime).GetTotalMilliseconds())), ::ToString(options.Profile)); }