UE4 – HLSL texture sample quick tip

Software:
Unreal Engine 4.26

When sampling textures using an HLSL custom node,
The UE4 TextureObject input name, will automatically have a sampler object generated named:

<your TextureObject name>sampler

For example, if you named your TextureObject input “tex_in”, the available sampler will be named “tex_insampler”.
So the code for sampling the texture will be:

Texture2DSample(tex_in, tex_inSampler, coords);

The following is an example of a simple u-blur custom node code, with 4 node inputs:
1. tex_in – TextureObject
2. coords – float2
3. size – float
4. sample – float

int blur_samples = int(samples * 0.5f);
float3 col = 0.0f;
float2 sample_coords = 0.0f;
for (int i = -blur_samples; i < blur_samples; i ++)
{	
	sample_coords.x = i * (size / blur_samples * 2);
	col += Texture2DSample(tex_in, tex_inSampler, coords + sample_coords ) / (blur_samples * 2);
}
return col;

The above code can typed directly in the Custom node’s Code field. or loaded from an external .usf file.

See also:
Loading HLSL shaders from the project folder

3ds max – Using a GradientRamp procedural texture in Mapped mode

Software:
3ds max 2020

Using the GradientRamp procedural texture map in Mapped mode can very useful for creating procedural material effects.
The Idea is that the lightness value from a different map will determine what part of the GradientRamp is sampled.

In this example the GradientRamp uses values produced by a procedural Falloff map set to Perpendicular-Parallel mode, as its coordinates source, to create richly colored metal that changes its Hue depending on View/Incident angle:

Annotation 2020-05-02 184426

In this example the GradientRamp uses values produced by a procedural Noise map as its coordinates source to create an irregular color effect:

Annotation 2020-05-02 184849

Note:
The examples here were rendered using V-Ray Next for 3ds max, but this technique could also be used with other rendering engines.

 

Related:

  1. 3ds max Island/seashore tip

Cycles render – Using the Normal Blue channel for top side effects

Software:
Blender 2.8 | Cycles Render

1.jpg

The shading normal‘s Z component can be easily used as a ready-to-use procedural mask for ‘covering effects’ like dust, snow, and if baked, also as a base for particle effects like debris and vegetation.

This simple shading flow example the shading normal‘s Z component, that represents how much the surface is facing upwards is separated , mixed (multiplied) with a noise textured and than fed into a ColorRamp Converter node for fine tuning the resulting mask:

2

This is the full shading flow of the snow effect in the image above:

3.jpg

After Effects – Camera Lens Blur effect

Software:
After Effects CC 2019

Untitled-2

Adobe After Effects has a very effective Camera Lens Blur effect that is capable of efficiently faking DOF (Depth Of Field) and Bokeh visual effects for 3D rendered images and animations, and also animate a fake “Focus-Pull”.

The effect will work best on 32 bit float EXR files, and requires a Z depth render element (pass/AOV) to be rendered with the main RGB image, and supplied as the Blur Map layer.

Tip:
If necessary, color correct the Z depth image so that the Black to White range will reflect the wanted focus range, and that the closest depth will be Black, blending into White at the furthest depth.

Example of a Z Depth image:Buddha_Z0.jpg

Untitled-3

Radius:
Controls the blurriness

Shape:
Choose the lens iris shape (number of blades) to design the Bokeh effect

Blur Map:
Defines a black & White Depth Layer (Z Depth) where black is the closes point to the camera and white is the furthest.

Blur Focal Distance:
Values of 0.0 to 1.0 will have the black through grey to white areas of the Blur Map remain at focus (sharp)

Highlight > Gain:
Intensify the highlights to create a more dominant Bokeh effect

 

Untitled-2.jpg

 

Related:
DOF in Arnold for Maya