TransWikia.com

Sending light data from Vertex Shader to Pixel Shader?

Game Development Asked on November 2, 2021

We have a pixel shader constant buffer that contains the light data for the item that is currently rendered.

To implement tangent space normal mapping, i would need to transform each light into tangent space.

Is it a valid approach to instead bind the light data to the vertex shader and then send the transformed Light Data to the pixel shader since the vertex shader runs less frequently than the pixel shader?

As a side note: I am using forward rendering with a limited light count.
Our pixel shader constant buffer looks like this:

struct RendererLight {
    float3 Position;
    float3 Color;
    float3 Direction;
    float Intensity;
    float In;
    float Out;
    float Range;
};

cbuffer LightsBuffer : register(b2)
{
    RendererLight Lights[8];
    uint NumLights;
};

One Answer

It's valid, but you have a limited number of interpolators between the two shader stages, and depending how much data you're sending you may bump into that limit. You'll almost certainly need to split your cbuffer in two - lights per-vertex and lights per-pixel - with the per-vertex buffer containing the bare minimum of data.

However, you should also bear in mind that modern GPUs are very unlikely to be ALU-bound with the number of computations you're currently doing, and that in certain cases you can almost treat ALU as if it were effectively free. Compare that to the trade-offs involved in splitting your cbuffer, complicating your shaders, and using those extra interpolators (which are very much not free) and you will probably be better off just leaving your shaders as they are.

Ultimately what it comes down is: have you benchmarked this, and is it actually a performance problem for you?

Answered by Maximus Minimus on November 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP