Linear Rendering

Linear Rendering

Overview

Linear rendering refers to the process of rendering a scene with all inputs being linear. Normally textures exist with gamma correction pre-applied to them, which means that when the textures are sampled in a material the values are not linear. If these textures are used in the usual equations for e.g. lighting and image effect it will lead to slightly wrong results as the equations are calculated in a non-linear space.

Linear rendering ensures that both inputs and outputs of a shader are in the correct color space which results in a more correct outcome.

Gamma Pipeline

In the gamma rendering pipeline all colors and textures are sampled in gamma space, ie, gamma correction is not removed from images or colors before they are used in a shader. Albeit these values being in gamma space, all shader calculations treat their input as if it was in linear space, and additionally, when writing the shader outputs to memory, no gamma correction is applied to the final pixel. Much of the time this looks acceptable as the two wrongs go some way to cancelling each other out. But it is not correct.

Linear Pipeline

If linear rendering is enabled then inputs to the shader program are supplied with the gamma correction removed from them. For colors this conversion is applied implicitly if you are in linear space. Textures are sampled using hardware sRGB reads; the source texture is supplied in gamma space and then on sampling in the graphics hardware the result is converted automatically. These inputs are then supplied to the shader and lighting occurs as it normally would. When writing the resulting value to the framebuffer, it will either be gamma corrected or left in linear space for later gamma correction; this depends on the current rendering configuration.

Differences Between Linear and Gamma Rendering

When using linear rendering, input values to the shader equations are different than in gamma space. This means that e.g. lights striking surfaces will have a different response curve and image effects will behave differently than in the gamma pipeline.

Light Falloff

The falloff from distance- and normal-based lighting is changed in two ways. Firstly when rendering in linear mode, the additional gamma correction that is performed will make a light‘s radius appear larger. Secondly lighting edges will also be harsher. This more correctly models lighting intensity falloff on surfaces.

Linear Intensity Response

When you are using gamma rendering, the colors and textures that are supplied to a shader have a gamma correction applied to them. When they are used in a shader the colors of high luminance are actually brighter then they should be for linear lighting. This means that as light intensity increases the surface will get brighter in a non linear way. This leads to lighting that can be too bright in many places, and can also give models and scenes a washed-out feel. When you are using linear rendering, the response from the surface remains linear as the light intensity increases. This leads to much more realistic surface shading and a much nicer color response in the surface.

Infinite 3D Head Scan by Lee Perry-Smith is licensed under a Creative Commons Attribution 3.0 Unported License. Available from: http://www.ir-ltd.net/

Linear and Gamma Blending

When performing blending into the framebuffer, the blending occurs in the color space of the framebuffer. When using gamma rendering, this means that non-linear colors get blended together. This is incorrect. When using linear space rendering, blending occurs in linear space. This is correct and gives the expected results.

Using Linear Rendering

Linear rendering gives a different look to the rendered scene. When you have authored a project for rendering in gamma space, at first it will most likely not look correct if you change to linear rendering. Because of this, if you move to linear rendering from gamma rendering it may take some time to update the project so that it looks as good as before, but the switch ultimately enables more consistent and realistic rendering. That being said, enabling linear rendering in Unity is simple: It is implemented on a per-project basis and is exposed in the Player Settings which can be located at?Edit -> Project Settings -> Player -> Other Settings

Lightmapping

When you are using linear rendering, all lighting and textures are linearized, which means that the values passed to the lightmapper also need to be modified. Thus, when you switch between gamma and linear rendering, you will need to rebake lightmaps. This happens automatically when Unity‘s lighting is set to auto bake (which is the default).

Supported Platforms

Linear rendering is not supported on all platforms. The build targets that currently support the feature are:

  • Windows, Mac and Linux (standalone and web player)
  • Xbox 360, Xbox One
  • PlayStation 3 and 4

    Even though the desktop platforms generally support linear rendering, in some cases it may be disabled due to graphics driver issues. You can check this by looking at?QualitySettings.desiredColorSpace?and?QualitySettings.activeColorSpace. If the desired color space is linear but the active color space is gamma then the player has fallen back to gamma space. This can be used to inform the user that the application will not look correct for them or to force an exit from the player.

    Linear and Non HDR

    When you are not using HDR, a special framebuffer type is used that supports sRGB read and sRGB write (Degamma on read, Gamma on write). This means that just like a texture, the values in the framebuffer are gamma corrected. When this framebuffer is used for blending or bound as texture, the values have the gamma removed before being used. When these buffers are written to, the value that is being written is converted from linear space to gamma space. If you are rendering in linear mode then all post-process effects will have their source and target buffers created with sRGB reading and writing enabled so that post-processing and post-process blending occurs in linear space.

    Linear and HDR

    When using HDR, rendering is performed into floating point buffers. These buffers have enough resolution not to require conversion to and from gamma space whenever the buffer is accessed. This means that when rendering in linear mode, the render targets you use will store the colors in linear space. Therefore, all blending and post process effects will implicitly be performed in linear space. When the the backbuffer is written to, gamma correction is applied.

    GUI and Linear Authored Textures

    Rendering elements of the?Legacy GUI System?is always done in gamma space. This means that, for the legacy GUI system, GUI textures should not have their gamma removed on read. This can be achieved in two ways:

  • Set the texture type to GUI in the texture importer
  • Check the ‘Bypass sRGB Sampling‘ checkbox in the advanced texture importer

    It is also important that lookup textures, masks, and other textures whose RGB values mean something specific and have no gamma correction applied to them should bypass sRGB sampling. This will cause the sampled texture not to remove gamma before it is used in the shader, and calculations will be done with the same value as is stored on disk.

时间: 2024-11-06 23:10:59

Linear Rendering的相关文章

【浅墨Unity3D Shader编程】之十一 深入理解Unity5中的Standard Shader(三)&屏幕像素化特效的实现

本系列文章由@浅墨_毛星云 出品,转载请注明出处.   文章链接:http://blog.csdn.net/poem_qianmo/article/details/50095705 作者:毛星云(浅墨)    微博:http://weibo.com/u/1723155442 本文工程使用的Unity3D版本: 5.2.1  概要:续接上文,本文进一步讲解与分析了上文未讲完的Unity5中Standard Shader正向基础渲染通道源码的片段着色实现部分,以及对屏幕像素化后期特效进行了实现. 同

关于 Unity WebGL 的探索(一)

到今天为止,项目已经上线一个多月了,目前稳定运行,各种 bug 也是有的.至少得到了苹果的两次推荐和 TapTap 一次首页推荐,也算是结项后第一时间对我们项目的一个肯定. 出于各种各样的可描述和不可描述之原因,我们现在需要把项目移植到 Web 端,第一次被告知这个需求时我直接给出了不可能的答复,之前从来没有考虑过这个平台的兼容性,现在项目算是做完了结果要这样折腾一番我觉得是需要消耗非常可怕的人力物力但未必能有很好的效果,性价比很低,但是最终我还是妥协了,硬着头皮接下来,也硬着头皮上,毕竟,技术

Unity引擎的Player Settings介绍

我用的是unity5.4.3版本的 一.窗口打开: 从菜单栏查看播放器设置,选择 Edit->Project Settings->Player 二.全局设置 第一部分: Company Name 公司名称 Product Name 产品名称,当游戏运行时,这个名字将出现在菜单栏.并且也被使用来设置参数文件. Default Icon 默认图标,将应用于每一个平台的默认图标,发布出来的项目图标(特定平台需要以后还可以覆盖这个). Default Cursor 就是鼠标移到相应的位置 鼠标形状为默

Player Settings 导出设置

Player Settings is where you define various parameters (platform specific) for the final game that you will build in Unity. Some of these values for example are used in the Resolution Dialog that launches when you open a standalone game, others are u

【U3D】播放器设置(PlayerSettings)

播放器设置 (Player Settings) 播放器设置 (Player Settings) 用于为您要在 Unity 中编译的最终游戏定义各项(特定于平台的)参数.例如,参数中的一些值用于您打开单机版游戏时启动的分辨率对话框 (Resolution Dialog) 中,而在编译 iOS 设备游戏时 XCode 会使用其他值.因此,正确填写这些值十分重要. 要查看“播放器设置”(Player Settings),请从菜单栏选择编辑 (Edit) -> 项目设置 (Project Setting

Unity3d 屏幕空间人体皮肤知觉渲染&次表面散射Screen-Space Perceptual Rendering & Subsurface Scattering of Human Skin

之前的人皮渲染相关 前篇1:unity3d Human skin real time rendering 真实模拟人皮实时渲染 前篇2:unity3d Human skin real time rendering plus 真实模拟人皮实时渲染 plus篇 SSS:Unity3d shader之次表面散射(Subsurface Scattering) PBR:Unity3d 基于物理渲染Physically-Based Rendering之specular BRDF Screen-Space P

[ZZ] [siggraph10]color enhancement and rendering in film and game productio

原文link:<color enhancement and rendering in film and game production> 是siggraph 2010,“Color Enhancement and Rendering in Film and Game Production” course的一个paper. 从摄影到电影里面使用的技术,来启发游戏里怎么使用. 很不错的一个地方是:了解到了filmic tone mapping是怎么来的了,之前uncharted2的文章还看的我一头

Realtime Rendering 1.1

[Realtime Rendering 1.1] 1.A linear transform is one that preserves vector addition and scalar multiplication. Specifically, 24.Combining linear transforms and translations can be done using an affine transform. An affine transform is one that perfor

Spark MLlib Linear Regression线性回归算法

1.Spark MLlib Linear Regression线性回归算法 1.1 线性回归算法 1.1.1 基础理论 在统计学中,线性回归(Linear Regression)是利用称为线性回归方程的最小平方函数对一个或多个自变量和因变量之间关系进行建模的一种回归分析.这种函数是一个或多个称为回归系数的模型参数的线性组合. 回归分析中,只包括一个自变量和一个因变量,且二者的关系可用一条直线近似表示,这种回归分析称为一元线性回归分析.如果回归分析中包括两个或两个以上的自变量,且因变量和自变量之间