I am developing an application that allows to switch the RenderPipeline in runtime. The content of the application is also loaded in runtime, from AssetBundles containing a scene. Depending on the RenderPipeline for which the scene is published (Built-in, Universal or HighDefinition), it switches to the corresponding Renderer Pipeline before loading the scene.
There are some 3D models that are always seen in the application, and for them I have created a shader in SahderGraph that has the 3 render pipelines as Active Targets.
In Editor it works correctly, in PlayMode I can change the active RenderPipeline and these elements are still rendered correctly.
In runtime, these elements are only displayed correctly in Built-in render pipeline, in Universal and HighDefinition they are not rendered correctly.
Is what I am trying to do supported? Am I missing something?
I’m actually building for Built-in, but I have also tried setting urp or hdrp as target in Graphic settings and I got the same results.
The reason for trying to support multiple rendering pipelines is that we aren’t the only developers that build content for our app, and we want to allow other creators to build their own content using SRP if they want to.
Personally I was working with URP, and HDRP independently on different projects.
Some people has reported, that materials are different somehow, for these rendering pipelines. I don’t know if that is the case for you, but maybe be some hint.
Someone more knowlagable in rendering pipelines than me, would need to reply here.
In case this can help anyone in the future, the solution I have applied is as follows.
It seems that the ShaderGraph shaders are being stripped at build time, and the shaders are only compiled for the target RenderPipeline set in project settings at build time.
To fix this, I have done the following:
An editor tool to publish AssetBundles, which receives a list of materials, and a RenderPipelineAsset (Universal or HDRP). It publishes the materials by targeting the specified RenderPipeline.
At runtime, when switching to a URP or HDRP scene, the AssetBundle with the published materials for that RP is also loaded, and the materials of the GameObjects that use them are changed.
This works for me. It would be great if a ShaderGraph could work for all the RenderPipelines it targets and support runtime switching between RPs. Maybe making a custom shader preprocessor (Unity - Scripting API: IPreprocessShaders) and preventing stripping of any variant of the shader could be solved, although I imagine the build time would skyrocket.
It would be great if any Unity staff could look into this and give some insight.