Hy everyone. I’m working on GI inside UE4 (Realtime Dynamic GI + Reflections + AO + Emissive plugin - AHR - Game Development - Epic Developer Community Forums), but I’m stuck now with a problem that I hope someone is able to solve.
I created a bunch of diferent shaders that are used to render the objects, and as I didn’t find documentation, I created them copying the base pass shader classes.
For example, here’s the vertex shader class I use on the voxelization stage
class FAHRVoxelizationVertexShader : public FMeshMaterialShader
{
DECLARE_SHADER_TYPE(FAHRVoxelizationVertexShader,MeshMaterial);
protected:
FAHRVoxelizationVertexShader() {}
FAHRVoxelizationVertexShader(const FMeshMaterialShaderType::CompiledShaderInitializerType& Initializer):
FMeshMaterialShader(Initializer)
{
}
public:
static bool ShouldCache(EShaderPlatform Platform,const FMaterial* Material,const FVertexFactoryType* VertexFactoryType)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, const FMaterial* Material, FShaderCompilerEnvironment& OutEnvironment)
{
FMeshMaterialShader::ModifyCompilationEnvironment(Platform, Material, OutEnvironment);
}
virtual bool Serialize(FArchive& Ar)
{
bool bShaderHasOutdatedParameters = FMeshMaterialShader::Serialize(Ar);
return bShaderHasOutdatedParameters;
}
void SetParameters(
FRHICommandList& RHICmdList,
const FMaterialRenderProxy* MaterialRenderProxy,
const FVertexFactory* VertexFactory,
const FMaterial& InMaterialResource,
const FSceneView& View
)
{
FMeshMaterialShader::SetParameters(RHICmdList, GetVertexShader(),MaterialRenderProxy,InMaterialResource,View, ESceneRenderTargetsMode::DontSet);
}
void SetMesh(FRHICommandList& RHICmdList, const FVertexFactory* VertexFactory,const FSceneView& View,const FPrimitiveSceneProxy* Proxy,const FMeshBatchElement& BatchElement)
{
FMeshMaterialShader::SetMesh(RHICmdList, GetVertexShader(),VertexFactory,View,Proxy,BatchElement);
}
private:
};
and the shader
// @
#include "AHRCommon.usf"
#include "AHRVoxelizationCommon.usf"
void Main(
FVertexFactoryInput Input,
OPTIONAL_VertexID
out FAHRVoxelizationVSOut Output
)
{
FVertexFactoryIntermediates VFIntermediates = GetVertexFactoryIntermediates(Input);
float4 WorldPositionExcludingWPO = VertexFactoryGetWorldPosition(Input, VFIntermediates);
float3x3 TangentToLocal = VertexFactoryGetTangentToLocal(Input, VFIntermediates);
FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPositionExcludingWPO.xyz, TangentToLocal);
Output.FactoryInterpolants = VertexFactoryGetInterpolantsVSToPS(Input, VFIntermediates, VertexParameters);
Output.Position = WorldPositionExcludingWPO;
// add the material offset
ISOLATE
{
Output.Position.xyz += GetMaterialWorldPositionOffset(VertexParameters);
}
}
In this case, GetMaterialWorldPositionOffset(VertexParameters) returns 0 always, no mater what do you create on the material editor.
My question is what is wrong or what do I need to do to get that information inside my shader, so that I can drive the shader parameters trough the material editor. Things like world offset, or emissive color.
It would be awesome if someone can explain a bit how the stage from the material editor to the shader works, so for example, what things I need to set up to get the base color from the material editor, or the emissive color.
I tried looking at the shaders, and from what I can see, the material compiler replaces the %s inside the shader with code generated from the material ( at least I assume it does that), but an explanation will help a lot
Hope I was clear enough, but feel free to ask anything.
EDIT:
Here’s the code for AHRVoxelizationCommon.usf
// @
#include "Common.usf"
#include "BasePassCommon.usf"
#include "Material.usf"
#include "VertexFactory.usf"
struct FAHRVoxelizationVSOut
{
FVertexFactoryInterpolantsVSToPS FactoryInterpolants;
float4 Position : TEXCOORD7;
};
struct FAHRVoxelizationGSOut
{
FVertexFactoryInterpolantsVSToPS FactoryInterpolants;
float4 Position : SV_POSITION;
float3 wPos : TEXCOORD7;
};