UE编辑器灯光颜色,能量传入Shader流程

news2024/11/23 13:43:06

编辑器界面:

 

 代码流程:

FLinearColor ULightComponent::GetColoredLightBrightness() const
{
	// Brightness in Lumens
	float LightBrightness = ComputeLightBrightness();
	FLinearColor Energy = FLinearColor(LightColor) * LightBrightness;
	if (bUseTemperature)
	{
		Energy *= FLinearColor::MakeFromColorTemperature(Temperature);
	}

	return Energy;
}

	/** 
	 * Filter color of the light.
	 * Note that this can change the light's effective intensity.
	 */
UPROPERTY(BlueprintReadOnly, interp, Category=Light, meta=(HideAlphaChannel, ShouldShowInViewport = true))
	FColor LightColor;

FORCEINLINE FLinearColor::FLinearColor(const FColor& Color)
{
	R = sRGBToLinearTable[Color.R];
	G = sRGBToLinearTable[Color.G];
	B = sRGBToLinearTable[Color.B];
	A = float(Color.A) * (1.0f / 255.0f);
}

float ULightComponent::ComputeLightBrightness() const
{
	float LightBrightness = Intensity;

	if(IESTexture)
	{
		if(bUseIESBrightness)
		{
			LightBrightness = IESTexture->Brightness * IESBrightnessScale;
		}

		LightBrightness *= IESTexture->TextureMultiplier;
	}

	return LightBrightness;
}

FLinearColor FLinearColor::MakeFromColorTemperature( float Temp )
{
	Temp = FMath::Clamp( Temp, 1000.0f, 15000.0f );

	// Approximate Planckian locus in CIE 1960 UCS
	float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp );
	float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp );

	float x = 3.0f * u / ( 2.0f * u - 8.0f * v + 4.0f );
	float y = 2.0f * v / ( 2.0f * u - 8.0f * v + 4.0f );
	float z = 1.0f - x - y;

	float Y = 1.0f;
	float X = Y/y * x;
	float Z = Y/y * z;

	// XYZ to RGB with BT.709 primaries
	float R =  3.2404542f * X + -1.5371385f * Y + -0.4985314f * Z;
	float G = -0.9692660f * X +  1.8760108f * Y +  0.0415560f * Z;
	float B =  0.0556434f * X + -0.2040259f * Y +  1.0572252f * Z;

	return FLinearColor(R,G,B);
}
void FLightRenderParameters::MakeShaderParameters(const FViewMatrices& ViewMatrices, float Exposure, FLightShaderParameters& OutShaderParameters) const
{
	OutShaderParameters.TranslatedWorldPosition = FVector3f(ViewMatrices.GetPreViewTranslation() + WorldPosition);
	OutShaderParameters.InvRadius = InvRadius;
	OutShaderParameters.Color = FVector3f(Color) * GetLightExposureScale(Exposure);
	OutShaderParameters.FalloffExponent = FalloffExponent;
	OutShaderParameters.Direction = Direction;
	OutShaderParameters.SpecularScale = SpecularScale;
	OutShaderParameters.Tangent = Tangent;
	OutShaderParameters.SourceRadius = SourceRadius;
	OutShaderParameters.SpotAngles = SpotAngles;
	OutShaderParameters.SoftSourceRadius = SoftSourceRadius;
	OutShaderParameters.SourceLength = SourceLength;
	OutShaderParameters.RectLightBarnCosAngle = RectLightBarnCosAngle;
	OutShaderParameters.RectLightBarnLength = RectLightBarnLength;
	OutShaderParameters.RectLightAtlasUVOffset = RectLightAtlasUVOffset;
	OutShaderParameters.RectLightAtlasUVScale = RectLightAtlasUVScale;
	OutShaderParameters.RectLightAtlasMaxLevel = RectLightAtlasMaxLevel;
}
FLightSceneProxy::FLightSceneProxy(const ULightComponent* InLightComponent)
	: LightComponent(InLightComponent)
	, SceneInterface(InLightComponent->GetScene())
	, IndirectLightingScale(InLightComponent->IndirectLightingIntensity)
	, VolumetricScatteringIntensity(FMath::Max(InLightComponent->VolumetricScatteringIntensity, 0.0f))
	, ShadowResolutionScale(InLightComponent->ShadowResolutionScale)
	, ShadowBias(InLightComponent->ShadowBias)
	, ShadowSlopeBias(InLightComponent->ShadowSlopeBias)
	, ShadowSharpen(InLightComponent->ShadowSharpen)
	, ContactShadowLength(InLightComponent->ContactShadowLength)
	, SpecularScale(InLightComponent->SpecularScale)
	, LightGuid(InLightComponent->LightGuid)
	, RayStartOffsetDepthScale(InLightComponent->RayStartOffsetDepthScale)
	, IESTexture(0)
	, bContactShadowLengthInWS(InLightComponent->ContactShadowLengthInWS ? true : false)
	, bMovable(InLightComponent->IsMovable())
	, bStaticLighting(InLightComponent->HasStaticLighting())
	, bStaticShadowing(InLightComponent->HasStaticShadowing())
	, bCastDynamicShadow(InLightComponent->CastShadows && InLightComponent->CastDynamicShadows)
	, bCastStaticShadow(InLightComponent->CastShadows && InLightComponent->CastStaticShadows)
	, bCastTranslucentShadows(InLightComponent->CastTranslucentShadows)
	, bTransmission(InLightComponent->bTransmission && bCastDynamicShadow && !bStaticShadowing)
	, bCastVolumetricShadow(InLightComponent->bCastVolumetricShadow)
	, bCastHairStrandsDeepShadow(InLightComponent->bCastDeepShadow)
	, bCastShadowsFromCinematicObjectsOnly(InLightComponent->bCastShadowsFromCinematicObjectsOnly)
	, bForceCachedShadowsForMovablePrimitives(InLightComponent->bForceCachedShadowsForMovablePrimitives)
	, CastRaytracedShadow(InLightComponent->CastShadows == 0? (TEnumAsByte<ECastRayTracedShadow::Type>) ECastRayTracedShadow::Disabled : InLightComponent->CastRaytracedShadow)
	, bAffectReflection(InLightComponent->bAffectReflection)
	, bAffectGlobalIllumination(InLightComponent->bAffectGlobalIllumination)
	, bAffectTranslucentLighting(InLightComponent->bAffectTranslucentLighting)
	, bUsedAsAtmosphereSunLight(InLightComponent->IsUsedAsAtmosphereSunLight())
	, bAffectDynamicIndirectLighting(InLightComponent->bAffectDynamicIndirectLighting)
	, bUseRayTracedDistanceFieldShadows(InLightComponent->bUseRayTracedDistanceFieldShadows)
	, bUseVirtualShadowMaps(false)	// See below
	, bCastModulatedShadows(false)
	, bUseWholeSceneCSMForMovableObjects(false)
	, AtmosphereSunLightIndex(InLightComponent->GetAtmosphereSunLightIndex())
	, AtmosphereSunDiskColorScale(InLightComponent->GetAtmosphereSunDiskColorScale())
	, LightType(InLightComponent->GetLightType())	
	, LightingChannelMask(GetLightingChannelMaskForStruct(InLightComponent->LightingChannels))
	, StatId(InLightComponent->GetStatID(true))
	, ComponentName(InLightComponent->GetFName())
	, LevelName(InLightComponent->GetOwner() ? InLightComponent->GetOwner()->GetLevel()->GetOutermost()->GetFName() : NAME_None)
	, FarShadowDistance(0)
	, FarShadowCascadeCount(0)
	, ShadowAmount(1.0f)
	, SamplesPerPixel(1)
	, DeepShadowLayerDistribution(InLightComponent->DeepShadowLayerDistribution)
#if ACTOR_HAS_LABELS
	, OwnerNameOrLabel(InLightComponent->GetOwner() ? InLightComponent->GetOwner()->GetActorNameOrLabel() : InLightComponent->GetName())
#endif
{
	check(SceneInterface);

	// Currently we use virtual shadows maps for all lights when the global setting is enabled
	bUseVirtualShadowMaps = ::UseVirtualShadowMaps(SceneInterface->GetShaderPlatform(), SceneInterface->GetFeatureLevel());

	// Treat stationary lights as movable when non-nanite VSMs are enabled
	const bool bNonNaniteVirtualShadowMaps = UseNonNaniteVirtualShadowMaps(SceneInterface->GetShaderPlatform(), SceneInterface->GetFeatureLevel());
	if (bNonNaniteVirtualShadowMaps)
	{
		bStaticShadowing = bStaticLighting;
	}

	const FLightComponentMapBuildData* MapBuildData = InLightComponent->GetLightComponentMapBuildData();
	
	if (MapBuildData && bStaticShadowing && !bStaticLighting)
	{
		ShadowMapChannel = MapBuildData->ShadowMapChannel;
	}
	else
	{
		ShadowMapChannel = INDEX_NONE;
	}

	// Use the preview channel if valid, otherwise fallback to the lighting build channel
	PreviewShadowMapChannel = InLightComponent->PreviewShadowMapChannel != INDEX_NONE ? InLightComponent->PreviewShadowMapChannel : ShadowMapChannel;

	StaticShadowDepthMap = &LightComponent->StaticShadowDepthMap;

	if(LightComponent->IESTexture)
	{
		IESTexture = LightComponent->IESTexture;
	}
	 
	Color = LightComponent->GetColoredLightBrightness();
}
FDeferredLightUniformStruct GetDeferredLightParameters(const FSceneView& View, const FLightSceneInfo& LightSceneInfo)
{
	FDeferredLightUniformStruct Out;

	FLightRenderParameters LightParameters;
	LightSceneInfo.Proxy->GetLightShaderParameters(LightParameters);
	LightParameters.MakeShaderParameters(View.ViewMatrices, View.GetLastEyeAdaptationExposure(), Out.LightParameters);
}
struct FLightRenderParameters
{
	ENGINE_API void MakeShaderParameters(const FViewMatrices& ViewMatrices, float Exposure, FLightShaderParameters& OutShaderParameters) const;
	ENGINE_API float GetLightExposureScale(float Exposure) const;
	static ENGINE_API float GetLightExposureScale(float Exposure, float InverseExposureBlend);

	// Position of the light in world space.
	FVector WorldPosition;

	// 1 / light's falloff radius from Position.
	float InvRadius;

	// Color of the light.
	FLinearColor Color;

	// The exponent for the falloff of the light intensity from the distance.
	float FalloffExponent;

	// Direction of the light if applies.
	FVector3f Direction;

	// Factor to applies on the specular.
	float SpecularScale;

	// One tangent of the light if applies.
	// Note: BiTangent is on purpose not stored for memory optimisation purposes.
	FVector3f Tangent;

	// Radius of the point light.
	float SourceRadius;

	// Dimensions of the light, for spot light, but also
	FVector2f SpotAngles;

	// Radius of the soft source.
	float SoftSourceRadius;

	// Other dimensions of the light source for rect light specifically.
	float SourceLength;

	// Barn door angle for rect light
	float RectLightBarnCosAngle;

	// Barn door length for rect light
	float RectLightBarnLength;

	// Rect. light atlas transformation
	FVector2f RectLightAtlasUVOffset;
	FVector2f RectLightAtlasUVScale;
	float RectLightAtlasMaxLevel;

	float InverseExposureBlend;

	// Return Invalid rect light atlas MIP level
	static float GetRectLightAtlasInvalidMIPLevel() { return 32.f;  }
};

Shader对应代码:

FDeferredLightData SetupLightDataForStandardDeferred()
{



	FDeferredLightData LightData;
	LightData.TranslatedWorldPosition = GetDeferredLightTranslatedWorldPosition();
	LightData.InvRadius = DeferredLightUniforms_InvRadius;
	LightData.Color = DeferredLightUniforms_Color;
	LightData.FalloffExponent = DeferredLightUniforms_FalloffExponent;
	LightData.Direction = DeferredLightUniforms_Direction;
	LightData.Tangent = DeferredLightUniforms_Tangent;
	LightData.SpotAngles = DeferredLightUniforms_SpotAngles;
	LightData.SourceRadius = DeferredLightUniforms_SourceRadius;
	LightData.SourceLength =  1  > 0 ? DeferredLightUniforms_SourceLength : 0;
    LightData.SoftSourceRadius = DeferredLightUniforms_SoftSourceRadius;
	LightData.SpecularScale = DeferredLightUniforms_SpecularScale;
	LightData.ContactShadowLength = abs(DeferredLightUniforms_ContactShadowLength);
	LightData.ContactShadowLengthInWS = DeferredLightUniforms_ContactShadowLength < 0.0f;
	LightData.ContactShadowNonShadowCastingIntensity = DeferredLightUniforms_ContactShadowNonShadowCastingIntensity;
	LightData.DistanceFadeMAD = DeferredLightUniforms_DistanceFadeMAD;
	LightData.ShadowMapChannelMask = DeferredLightUniforms_ShadowMapChannelMask;
	LightData.ShadowedBits = DeferredLightUniforms_ShadowedBits;
	LightData.bInverseSquared =  1  > 0 && DeferredLightUniforms_FalloffExponent == 0;
	LightData.bRadialLight =  1  > 0;

	LightData.bSpotLight =  1  > 0;
	LightData.bRectLight =  1  == 2;

	LightData.RectLightBarnCosAngle = DeferredLightUniforms_RectLightBarnCosAngle;
	LightData.RectLightBarnLength = DeferredLightUniforms_RectLightBarnLength;
	LightData.RectLightAtlasMaxLevel = DeferredLightUniforms_RectLightAtlasMaxLevel;
	LightData.RectLightAtlasUVOffset = DeferredLightUniforms_RectLightAtlasUVOffset;
	LightData.RectLightAtlasUVScale = DeferredLightUniforms_RectLightAtlasUVScale;

	LightData.HairTransmittance = InitHairTransmittanceData();
	return LightData;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/751312.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数学建模-拟合算法

这里的线性函数指的是参数为线性&#xff0c;而不是变量为线性。 yabx^2是线性的 用的比较多的是多项式拟合和自己定义的 拓展资料&#xff1a;工具箱曲线拟合类型评价解释 文件-导出代码 自动生成的代码修改图名和标签 如果不收敛&#xff0c;自己要修改初始值&#xf…

ES 跨集群搜索 Cross-cluster search (CCS)

跨集群查询 跨集群搜索(cross-cluster search)使你可以针对一个或多个远程集群运行单个搜索请求。 例如&#xff0c;你可以使用跨集群搜索来筛选和分析存储在不同数据中心的集群中的日志数据。 环境准备 角色IP系统dev172.16.122.244CentOS 7.9prod172.16.122.245CentOS 7.9 ES…

记忆——记忆宫殿——地点桩

地点桩图片 室内物品放置方法——时钟放置法 https://www.zhihu.com/question/34549534 地点桩的扩展和记忆 我告诉你一个让记忆宫殿数量翻125倍的方法&#xff0c;以后用一个地点桩就扔一个。 这方法是我在背了几本书后才在偶然中发现的&#xff0c;我叫他“五行推演法”&a…

ES(1)简介和安装

文章目录 简介倒排索引 安装 简介 ES是面向文档型数据库&#xff0c;一条数据在这里就是一个文档。 和关系型数据库大致关系如下: ES7.x中废除掉Type&#xff08;表&#xff09;的概念 倒排索引 要知道什么是倒排索引&#xff0c;就要先知道什么是正排索引 idcontent100…

判断数组中所有元素是否均为True numpy.alltrue()

【小白从小学Python、C、Java】 【计算机等级考试500强双证书】 【Python-数据分析】 判断数组中所有元素是否均为True numpy.alltrue() [太阳]选择题 请问关于以下代码的说法错误的是&#xff1f; import numpy as np print(【执行】np.alltrue([True, True, True])) print(n…

C/C++图形库EasyX保姆级使用教程(四) 图片的展示与缩放

C/C图形库EasyX保姆级使用教程 第一章 Microsoft Visual Studio 2022和EasyX的下载及安装使用 第二章 图形化窗口设置以及简单图形的绘制 第三章 图形颜色的填充及相关应用 第四章 图片的展示与缩放 文章目录 C/C图形库EasyX保姆级使用教程前言一、图片的展示1.变量存储图片2.…

安全测试方法介绍(下)渗透测试

安全主要测试方法主要有&#xff1a;静态源代码审查&#xff0c;这个在编码阶段就可以进行&#xff0c;这个阶段如果出现问题&#xff0c;修复起来成本也比较低。程序发布之后可以进行渗透测试。前面的文章中我们为大家介绍了静态源代码审查的方法和策略&#xff0c;接下来本文…

【milvus】向量数据库,用来做以图搜图+人脸识别的特征向量

1. 安装milvus ref:https://milvus.io/docs 第一次装东西&#xff0c;要把遇到的问题和成功经验都记录下来。 1.Download the YAML file wget https://github.com/milvus-io/milvus/releases/download/v2.2.11/milvus-standalone-docker-compose.yml -O docker-compose.yml看…

微信小程序中常见组件的使用

文章目录 微信小程序中常见组件的使用视图组件viewscroll-viewswipermovable-area 基础组件icontextrich-textprogress 表单组件buttoncheckbox、checkbox-grouplabelforminputpicker单列选择器多列选择器时间选择器&日期选择器&地区选择器 picker-viewradiosliderswit…

人工智能-神经网络

目录 1 神经元 2 MP模型 3 激活函数 3.1 激活函数 3.2 激活函数作用 3.3 激活函数有多种 4、神经网络模型 1 神经元 神经元是主要由树突、轴突、突出组成&#xff0c;树突是从上面接收很多信号&#xff0c;经过轴突处理后传递给突触&#xff0c;突触会进行选择性向下一级的…

[项目实战] 使用Idea构建单页面Vue3项目(不使用node、npm)

前言 某天张三对小花说&#xff0c;我需要在一台新电脑上实现一个前端的漂亮页面&#xff1a;比如京东手机首页(m.jd.com)。 小花这时吭哧吭哧的去新电脑上安装nodejs、npm&#xff0c;然后在本地使用npm构建vue3项目&#xff0c;在项目里下载安装element-plus、axios。下一步…

常用异常检测算法总结与代码实现[统计学方法/K近邻/孤立森林/DBSCAN/LOF/混合高斯GMM/自编码器AutoEncoder等]

这篇博文主要是延续前文系列的总结记录&#xff0c;这里主要是总结汇总日常主流的异常检测算法相关知识内容。 &#xff08;1&#xff09;基于统计方法的异常值检测 基于统计方法的异常值检测是一种常用的异常检测算法&#xff0c;它基于样本数据的统计特性来识别与其他样本显…

【RS】ENVI5.6 栅格数据坐标转换

ENVI是一个完整的遥感图像处理平台&#xff0c;广泛应用于科研、环境保护、气象、农业、林业、地球科学、遥感工程、水利、海洋等领域。目前ENVI已成为遥感影像处理的必备软件&#xff0c;包含辐射定标、大气校正、镶嵌裁剪、分类识别、阈值分割等多种功能。ENVI针对绝大部分的…

【三相STATCOM】使用D-Q控制的三相STATCOM技术【三相VSI STATCOM为R-L负载提供无功功率】(Simulink实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

COMEN 科曼C60、C80心电监护仪协议对接

通过网口&#xff0c;成功对接到参数&#xff1a; HR、NibpDia、NibpMean、NibpSys、Spo2、Resp、Sys、Dia、Mean、Temp、PR等数值

flutter开发实战-flutter二维码条形码扫一扫功能实现

flutter开发实战-flutter二维码条形码扫一扫功能实现 flutter开发实战-flutter二维码扫一扫功能实现&#xff0c;要使用到摄像头的原生的功能&#xff0c;使用的是插件&#xff1a;scan 效果图如下 一、扫一扫插件scan # 扫一扫scan: ^1.6.01.1 iOS权限设置 <key>NSCa…

移动互联网时代的网络口碑营销怎么做

从人类开始交换商品的时代开始&#xff0c;口碑营销就已经存在&#xff0c;是靠口耳传播的营销方式。小马识途认为进入当今移动互联网时代&#xff0c;口碑营销又有了新的发展&#xff0c;网络口碑营销推广开始普及。营销人员将传统口碑营销与移动互联网营销相结合&#xff0c;…

在arm平台上安装qt

qt官网上如果没有找到对应的安装包&#xff0c;就需要下载源代码自行编译安装qt&#xff0c;时间会久一点 qt下载 进入官网下载 如下图步骤选择源代码包&#xff08;以5.12.12为例&#xff09; 可以复制链接地址在迅雷上创建下载任务&#xff0c;下载速度会快些 qt的编译与…

基于Javaweb实现ATM机系统开发实战(十)取款功能实现

老规矩&#xff0c;先看前端页面&#xff1a; <% page language"java" contentType"text/html; charsetUTF-8" pageEncoding"UTF-8"%> <% taglib prefix"c" uri"http://java.sun.com/jsp/jstl/core" %> <!D…

B069-项目实战-店铺入驻-FastDfs-邮件

目录 店铺入驻课堂笔记data表结构自定义业务异常impl 图片上传-fastdfs应用背景概念理论入门案例项目使用1.导包2.添加配置文件3.导入工具类4.写接口将工具类暴露给前端使用5.前端部分 审核邮件通知1.导入jar包2.配置3.发送邮件邮件激活登录账号 店铺入驻 到平台来注册店铺信息…