UDK中的环境反射

 

In this tutorial we'll learn how to setup both a Dynamic (realtime) and a Static reflection material in Unreal Development Kit, and create a Parameter Switch to switch from Dynamic to Static reflections, or vice versa in UDK. For the tutorial I'll be using the February 2011 version of UDK.

In UDK, Reflections are nothing but Environments that are captured and projected inversely on the surface of objects, and are captured by using Screencapture Actors in UDK. You need to place this actor to capture the Scene or Environment of your Map and store it in a Special Texture format called Render to Target, this texture should be in the Content browser. It could be a Realtime or Static texture which can be used in a Material and set it up accordingly to get reflections on certain meshes like Metal or Glass.

To better understand and to function the Reflection Actor properly, we need to have a fully developed Scene or a Map, so that it captures the surrounding environment objects. Load UDK and open the "VCTF-Necropolis.udk" map (or any map of your choice), but make sure your map is loaded with lots of object textures and lighting, it should be in UT3 folder in the installed directory of UDK, that isUDKGame\Content\Maps\UT3. So just get your map ready.

Go to View->Browser windows and then Actor Classes. Let's just merge this Actor Classes window with the Content browser window, so that we can go to the Actor Classes window directly from the Content browser window. To do that, just click the Docking menu right next to the File menu option and Click Docked. Once you click the docked option, the window should disappear and now we can load it from the Content browser directly.

In the Actor Classes window, go to Uncategorized->SceneCaptureCubeMapActor Select and Drag & Drop it into your scene, just like in the pic below. Just make sure you are placing this actor right in the center of lots of objects with good lighting, so that you'll get a nice reflection. Or else you might see some dark patches on this actor, or a simple black colored Sphere. This actor is not Viewable in game when we play this map.

After dragging and placing the above actor into your scene, you'll get a black or dark colored sphere object in your scene. It's for capturing the environment and will reflect like a mirror. But now the color is Black, because this actor stores all the reflection in a special texture map called Scene Render to Target, which is Dynamic and not yet assigned. Let's create that Dynamic texture then.

Go to the Content Browser and Create a new package called "Advanced_Reflection" (or any name you like.) Right-click in the Content Browser and create a New TextureRenderTargetCube. The difference Between Target 2d and Target Cube is that Cube will capture all the Axes of the environment and store it in Cubemap format. Where as Target 2d is to capture only one side of the face, which is good for a one sided Plane surface mesh such as a Ground or Floor mesh.

After clicking new TextureRenderTargetCube from the Right-click options, you'll get a window just like in the image to set the resolution of the texture. Make sure to set the resolution as low as you can, or else it might drain a lot of Memory if you're using it for a Real time scene.But for the time being we'll set it to 1024 to capture the high res Static reflection texture and then we'll revert it back to 256 later. Don't forget to name this texture as "RT_reflection". Hit OK and save the package. After pressing OK, you'll see a Green Texture in the content browser which is your Dynamic texture that we named RT_reflection in the Content Browser.

Now that we have our Dynamic Texture ready, let's apply it onto the Scene capture Cubemap Actor in the scene.

Select that newly created dynamic texture named RT_reflection from the Content Browser, and now go back to your scene and Select the SceneCaptureCubeMap Actor (the black sphere) and hit F4 to open it's Properties. Just Collapse Scene Capture Actor->Scene Capture->Capture Properties and assign the Texture Target by clicking the green Arrow right next to it. You'll get half reflection and half black on the Sphere, to render everything you need to set the range that is by setting the FarPlane value to999999 (or as high as you can) like in the image above. Also Check/Tick Enable Fog and Enable Post process if you have any in your scene, or Check/Tick the Use Main Scene Post Process Settings value. I have enabled all the highlighted values in the above image.

Now if you open up your Content Browser, you'll see the Green Texture in the content browser now shows some Texture information and that Texture information is the Dynamic reflection of your scene. With this texture you can simply setup a material, as well as create a new Static Texture. Let's setup a material but we need to have a Static mesh to apply this material to.

For this tutorial I've created two Simple Geometry meshes that are a Sphere and Cylinder, as shown above. I'll use the Cylinder for Dynamic Realtime reflections, and the Sphere for Static reflections. So let's create a Static Reflection Texture now.

Right click on that Dynamic texture in the Content Browser and then click on Create New Static Texture. A window will Pop-up to name the new static texture that it will create. Just name it anything you want, but for this tutorial I'll name it "ST_reflection" and as shown above in Grouping Field. Simply type "Textures", so it will put the new texture in a sub category named Textures of Advanced_reflection package. After hitting OK, it will take some time to create the Static Cubemap texture in the Content Browser, wait for some time and then save the package.

After Creating the Static Cubemap Texture named ST_reflection, you should also have a few other textures with the same name, just don't delete them because it's a supporting texture which has all 6 sides of the reflection information. That is from minus X to positive X for example (suffixed as Neg and Pos) compiled in your ST_reflection texture. Now that we have Dynamic and Static textures that are RT_reflection and ST_reflection, it's time to create their material.

Right-click in the Content Browser and create a new material called "Reflection" (or any name you wish.)

Double click on your newly created material that is the Reflection material. Setting up the Reflection material in the material editor window is easy, but here I'll be setting up two types of reflection. That is Dynamic and Static Reflection as you can see the setup in the above image. This is useful when you want Static reflections on specific walls, ceilings or sometimes on the ground when you create an instance material or a child of this Material which we'll be doing it later. So let's setup the Reflection material for both Static and Dynamic.

The Following method is just the setup of the Dynamic and Static Reflection with a Switch parameter to enable or disable the type of reflection we want in material instance. You may use it with your current material setup or blend it with your current Diffuse Metal, Glass or any material you like.

Dynamic Material Setup: In the above image, the Dynamic setup has three connections and it goes by ReflectionVector>Transforms>RT_reflection. Let's setup the Dynamic reflection first, import the Dynamic texture (RT_reflection) into the Material Editor window and search for the Transform and ReflectionVector expressions. And then Connect the Reflection Vector node into the Vector Transform node, then ultimately plug the Vector transform node into the UVs of the Texture Sample Node, that is the RT_reflection Texture. Select all the nodes and comment Dyanmic_reflection (Right-click and New comment) then make a copy of this whole Dynamic reflection setup.

Static Material Setup: The Static Material Setup is almost the same except for the Texture Sample Node that is the RT_Reflection texture. Replace it with the ST_reflection Texture of the copied Dynamic_reflection Setup. Change the comment from Dynamic_reflection to Static_reflection, just like the setup in the above image.

Now we need a Switch to switch from Dynamic to Static or vice versa. To do that, just search for the Static switch parameter in the Material Expression window and drag it into your screen, or just Right-click in the material editor and then select FunctionUtility-> New Static Switch. Plug the ST_reflection to False, and RT_reflection to True for this switch. You can now plug this Switch into the Diffuse or Emissive channel, or you can even blend it with your current material setup by using Lerp (linear interpolation) expression node.

Static Switch Parameter: This switch has two inputs, TRUE and FALSE. Although its self-explanatory, but it will only render FALSE as a Default value and the True input value is ignored. So to change that, click on the Static Switch parameter and then on the properties window below, check or enable the Default Value, like in the image above and give it a Parameter name such as Static/Dynamic. Now Save and close the material editor window.

Just go to the Content Browser and Right-click on this newly created reflection material and click on Create New Material Instance (Constant). After that a window will appear to name the new material instance. Just name it "Static_reflection" and follow the above process again, but this time name it "Dynamic_reflection" for the second Material Instance.

Now you have two instances of the material in the content browser, Double-click on both material instances.
As in the above image, on the left side it's the static material and on the right it's the Dynamic material. Under Parameter Groups there is a Static/Dynamic checkbox, just make sure that it's left checkbox is checked for the Static Material. And the Right Checkbox is checked for the Dynamic Material as shown in the imag above. This parameter Static/Dynamic is created just because of the Switch we created in the Material editor window earlier. Once done with the settings, it's now time to assign these materials to our static meshes. So, just close those Material instance editor windows.

Go to the Content Browser and search for a Cylinder and Sphere mesh that I created for this tutorial. Apply the Dynamic material to the Cylinder and the Static material to the Sphere mesh, as shown in the above image. That's it! You're almost done, just place these two meshes in your map now.

Place the Cylinder mesh right above the realtime Reflection actor and place the Sphere mesh anywhere you wish, or you can place it next to the cylinder, side by side. Now test play inside your Editor.

As you can see in the above image. If you look at the cylinder you'll see a little bit of distorted reflection of your character, that's because of the curvature of the cylinder. The smoother the mesh, the better the reflection will be, but no changes on the reflection of the Sphere. Which still looks real, so it's a good way to fake reflection like this and also optimize. Dynamic Realtime reflections are used very rarely and it uses a lot of GPU and CPU power to render every frame. Be careful with the realtime reflection actor and its settings, UDK might crash often if you constantly make changes to the Realtime reflection actor that is the Scene capture actor. Make sure you save every step, or with any changes that you make. Test play in your viewport every time and make changes accordingly to get the desire effect.

Using Dynamic real-time Reflections in such a huge map with a large exterior scene or environment, will drain your memory and it may even crash a lot. So use it wisely and efficiently. Dynamic Reflection are often used in an indoor map, which has small set rooms with lots of mirrors reflecting interiors (such as Mirror door and Windows or Chrome Metals.) But you can still fake those reflection by using a simple switch to Static reflections, which is a smart and better way of doing it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值