和ue不同,ue是通过文件名传相应的参数到shader,比如
LoadShaderSourceFileChecked(TEXT(“/Engine/Private/MaterialTemplate.ush”), GetShaderPlatform(), MaterialTemplate);
可知MaterialTemplate.ush文件关联HLSLMaterialTranslator.cpp
但是,filament是个小巧的引擎,所以直接传参数就行了,
以沙盒为例
设置后可以调试下。
那么左边的参数是如何传递的呢?
通过
struct SandboxParameters {
const Material* material[MATERIAL_COUNT];
MaterialInstance* materialInstance[MATERIAL_COUNT];
sRGBColor color = {0.69f, 0.69f, 0.69f};
float alpha = 1.0f;
float roughness = 0.6f;
float metallic = 0.0f;
float reflectance = 0.5f;
float clearCoat = 0.0f;
float clearCoatRoughness = 0.0f;
float anisotropy = 0.0f;
float thickness = 1.0f;
float subsurfacePower = 12.234f;
float glossiness = 0.0f;
float specularAntiAliasingVariance = 0.0f;
float specularAntiAliasingThreshold = 0.0f;
float transmission = 1.0f;
float distance = 1.0f;
float ior = 1.5;
float emissiveExposureWeight = 1.0f;
float emissiveEV = 0.0f;
float sheenRoughness = 0.0f;
sRGBColor transmittanceColor = { 1.0f };
sRGBColor specularColor = { 0.0f };
sRGBColor subsurfaceColor = { 0.0f };
sRGBColor sheenColor = { 0.0f, 0.0f, 0.0f };
sRGBColor emissiveColor = { 0.0f };
int currentMaterialModel = MATERIAL_MODEL_LIT;
int currentBlending = BLENDING_OPAQUE;
bool ssr = false;
bool castShadows = true;
sRGBColor lightColor = {0.98f, 0.92f, 0.89f};
float lightIntensity = 110000.0f;
math::float3 lightDirection = {0.6f, -1.0f, -0.8f};
float iblIntensity = 30000.0f;
float iblRotation = 0.0f;
float sunHaloSize = 10.0f;
float sunHaloFalloff = 80.0f;
float sunAngularRadius = 1.9f;
bool directionalLightEnabled = true;
utils::Entity light;
utils::Entity spotLight;
bool hasSpotLight = false;
bool spotLightEnabled = false;
sRGBColor spotLightColor = {1.0f, 1.0f, 1.0f};
float spotLightIntensity = 200000.0f;
bool spotLightCastShadows = true;
math::float3 spotLightPosition;
float spotLightConeAngle = 3.14159 / 4.0f;
float spotLightConeFade = 0.9f;
bool hasDirectionalLight = true;
bool fxaa = true;
bool msaa = false;
bool dithering = true;
bool stableShadowMap = false;
float normalBias = 1.0;
float constantBias = 0.001;
float polygonOffsetConstant = 0.5;
float polygonOffsetSlope = 2.0;
View::AmbientOcclusionOptions ssaoOptions;
View::BloomOptions bloomOptions;
View::FogOptions fogOptions;
View::TemporalAntiAliasingOptions taaOptions;
bool screenSpaceContactShadows = false;
int stepCount = 8;
float maxShadowDistance = 0.3;
float cameraAperture = 16.0f;
float cameraSpeed = 125.0f;
float cameraISO = 100.0f;
bool colorGrading = true;
ColorGradingOptions colorGradingOptions;
};
static SandboxParameters g_params;
初始化。
首先初始化材质
可知,用的是opengl.
代码分析先到此打住,主要是要看传参到shader的内容。打开这些shader文件。
先看材质
c++中在这里传参给MaterialInstance。