# Physically-Based Rendering and lots of other lighting and materials upgrades (in Castle Game Engine and X3D 4.0)

**URL:** https://forum.castle-engine.io/t/physically-based-rendering-and-lots-of-other-lighting-and-materials-upgrades-in-castle-game-engine-and-x3d-4-0/129
**Category:** News
**Created:** [March 7, 2020, 11:54pm UTC](https://forum.castle-engine.io/t/physically-based-rendering-and-lots-of-other-lighting-and-materials-upgrades-in-castle-game-engine-and-x3d-4-0/129 "2020-03-07T23:54:14Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [March 7, 2020, 11:54pm UTC](https://forum.castle-engine.io/t/physically-based-rendering-and-lots-of-other-lighting-and-materials-upgrades-in-castle-game-engine-and-x3d-4-0/129/1 "2020-03-07T23:54:14Z")

</div>

| [![DamagedHelmet_0](https://castle-engine.io/wp/wp-content/uploads/2020/03/DamagedHelmet_0-200x113.png)](https://castle-engine.io/wp/wp-content/uploads/2020/03/DamagedHelmet_0.png "DamagedHelmet\_0") |
| [![FlightHelmet_0](https://castle-engine.io/wp/wp-content/uploads/2020/03/FlightHelmet_0-200x113.png)](https://castle-engine.io/wp/wp-content/uploads/2020/03/FlightHelmet_0.png "FlightHelmet\_0") |
| [![metallic_roughness_gltf_sample_viewer](https://castle-engine.io/wp/wp-content/uploads/2020/03/metallic_roughness_gltf_sample_viewer-200x89.png)](https://castle-engine.io/wp/wp-content/uploads/2020/03/metallic_roughness_gltf_sample_viewer.png "metallic\_roughness\_gltf\_sample\_viewer") |
| [![metallic_roughness_view3dscene](https://castle-engine.io/wp/wp-content/uploads/2020/03/metallic_roughness_view3dscene-200x113.png)](https://castle-engine.io/wp/wp-content/uploads/2020/03/metallic_roughness_view3dscene.png "metallic\_roughness\_view3dscene") |
| [![bump_mapping_test_0](https://castle-engine.io/wp/wp-content/uploads/2020/03/bump_mapping_test_0-200x113.png)](https://castle-engine.io/wp/wp-content/uploads/2020/03/bump_mapping_test_0.png "bump\_mapping\_test\_0") |
| [![metallic_roughness_0](https://castle-engine.io/wp/wp-content/uploads/2020/03/metallic_roughness_0-200x113.png)](https://castle-engine.io/wp/wp-content/uploads/2020/03/metallic_roughness_0.png "metallic\_roughness\_0") |

During the last few months, I was working with the [Web3D Consortium](https://www.web3d.org/) to bring many material and lighting upgrades to the next version of [X3D](https://castle-engine.io/vrml_x3d.php) and of course to our _Castle Game Engine_.

I’m proud to officially announce the first results of this work, including implementation of many new rendering features in _Castle Game Engine_!

The initial documentation is [summarized on this page – “X3D version 4: New features of materials, lights and textures”](https://github.com/michaliskambi/x3d-tests/wiki/X3D-version-4:-New-features-of-materials,-lights-and-textures). With time, more documentation will appear in CGE, and of course X3D v4 specification will also eventually be available as a definite reference of this. The examples are [in my x3d-tests repository, in pbr/ subdirectory](https://github.com/michaliskambi/x3d-tests/).

New features:

- Physically-based rendering (PBR) using the new `PhysicalMaterial` node.
- Ability to render glTF models with physical materials. Test it by opening [any glTF 2.0 sample model](https://github.com/KhronosGroup/glTF-Sample-Models/) with any engine tool. You can e.g. try [view3dscene from snapshots](https://michalis.ii.uni.wroc.pl/view3dscene-snapshots/).
- Much enhanced classic (Phong) lighting model thanks to the enhanced `Material` node with lots of new fields for textures (`emissiveTexture`, `normalTexture`, `specularShininessTexture`, `ambientTexture`),
- More natural “unlit” rendering using the new `UnlitMaterial` node (very useful for 2D games, and better than previous approach of _“Material with only emissiveColor non-zero”_, see [Why is UnlitMaterial useful](https://github.com/michaliskambi/x3d-tests/wiki/Why-is-UnlitMaterial-useful) for the detailed reasoning), 

- Image-based lighting using `EnvironmentLight` node. This is in-progress now (not yet working).

All of this is implemented in CGE. We get latest X3D features in this area, while also becoming a reference implementation of these X3D concepts.

## Backward compatibility

This change also pushed many fixes to the existing lighting shaders, to be pretty and 100% correct (in regards to both X3D 3 and X3D 4). This means:

- [SeparateDiffuseTexture](https://castle-engine.io/apidoc-unstable/html/CastleRenderer.TRenderingAttributes.html#SeparateDiffuseTexture) is now _always “on”_. This means that X3D `Appearance.texture` multiplies only diffuse factor (in Phong shading). So the `emissiveColor` or `specularColor` are not affected by the `Appearance.texture`.

- Using Material with _only emissiveColor non-zero_ behaves now 100% correctly, following X3D equations.
