Content and Context 内容和上下文 Standard Shader系列2

本文深入解析Unity中的Content(内容)和Context(上下文)在光照中的应用,涵盖天空盒、全局光照、反射探头、标准着色器及材质编辑器等内容,帮助理解对象如何受场景光照影响并呈现最终效果。
摘要由CSDN通过智能技术生成

Content and Context 内容和上下文

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.3版本
参考链接:https://docs.unity3d.com/Manual/StandardShaderContextAndContent.html

When thinking about lighting in Unity, it is handy to divide the concepts into what we call the content the item being lit and rendered, and the context, which is the lighting that exists in the scene which affects the object being lit.
当我们在Unity中考虑光照的时候,很容易将概念划分为被照明和渲染的内容,以及上下文:即存在于场景中的影响被照明对象的灯光。

The Context 上下文

When lighting an object it is important to understand which sources of light are affecting the object. There are usually direct light sources in your scene: Game Object lights that you may have placed around your scene. There are also indirect light sources such as reflections and bounced light. These all have an effect on the object’s material to give the final result that the camera sees across the surface of the object.
当照明一个物体时,重要的是要了解哪些光源在影响这个物体。在你的场景中通常有直接光源:可能在场景周围放置的光源游戏对象。也有间接光源,如反射和反弹光照。所有这些都会对物体的材质产生影响,从而使摄像机能看到物体表面的最终效果。

This is not a hard and fast separation, often what might be considered “content” could also be the part of the lighting context for another object.
这并不是可以快速分离的,通常被认为是“内容”的也可能是另一个对象的光照上下文。

A good example of this would be a building situated in a desert landscape. The building would take light information from the skybox, and perhaps bounced light from the surrounding ground.
一个很好的例子是坐落在沙漠景观中的建筑。建筑将从空中接收光照信息,可能还会从周围的地面反弹光照。

However there may be a character standing near an exterior wall of the building. For this character, the building is part of the lighting context - it may

大家好,今天给大家分享一下Android里的Context的一些用法. 这里大致可以分为两种:一是传递Context参数,二是调用全局的Context. 其实我们应用启动的时候会启动Application这个类,这个类是在AndroidManifest.xml文件里其实是默认的 为了让大家更容易理解,写了一个简单的Demo.步骤如下: 第1步:新建一个Android工程ApplicationDemo,目录结构如下: 第2步:新建一个工具类ToolsUtil.java,代码如下 package com.tutor.application; import android.content.Context; import android.widget.Toast; /** * @author carlshen. * 应用的一些工具类. */ public class ToolUtils { /** * 参数带Context. * @param context * @param msg */ public static void showToast(Context context,String msg){ Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } /** * 调用全局的Context. * @param msg */ public static void showToast(String msg){ Toast.makeText(MainApplication.getContext(), msg, Toast.LENGTH_SHORT).show(); } } 第3步:新建一个View命名为MainView.java就是我们Activity现实的View.代码如下: package com.tutor.application; import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.FrameLayout; /** * @author carlshen. * 自定义的MainView. */ public class MainView extends FrameLayout implements View.OnClickListener{ private Context mContext; private Activity mActivity; /** * 参数Button. */ private Button mArgButton; /** * 全局Button. */ private Button mGlobleButton; /** * 退出Button. */ private Button mExitButton; public MainView(Context context){ super(context); setupViews(); } public MainView(Context context, AttributeSet attrs) { super(context, attrs); setupViews(); } private void setupViews(){ //获取View的上下文. mContext = getContext(); //这里将Context转换为Activity. mActivity = (Activity)mContext; LayoutInflater inflater = LayoutInflater.from(mContext); View v = inflater.inflate(R.layout.main, null); addView(v); mArgButton = (Button)v.findViewById(R.id.arg_button); mGlobleButton = (Button)v.findViewById(R.id.glo_button); mExitButton = (Button)v.findViewById(R.id.exit_button); mArgButton.setOnClickListener(this); mGlobleButton.setOnClickListener(this); mExitButton.setOnClickListener(this); } public void onClick(View v) { if(v == mArgButton){ ToolUtils.showToast(mContext, "我是通过传递Context参数显示的!"); }else if(v == mGlobleButton){ ToolUtils.showToast("我是通过全局Context显示的!"); }else{ mActivity.finish(); } } } 这里MainView.java使用的布局main.xml代码如下: <?xml version="1.0" encoding="utf-8"?> 第4步:修改ApplicationDemoActivity.java,代码如下: package com.tutor.application; import android.app.Activity; import android.os.Bundle; public class ApplicationDemoActivity extends Activity { private static Context aContext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MainView mMainView = new MainView(this); setContentView(mMainView); aContext = getApplicationContext(); } /**获取Context. * @return */ public static Context getContext(){ return aContext; } } 第5步:运行上述工程效果如下:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值