Deferred rendering and ellipsoid point light

This topic is 734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi there,

I am using Unity and trying to change the lighting in deferred rendering that's why I am editing this : UnityDeferredLibrary.cginc
I would like to be able to apply the scaling to deform point lights and have a more ellipsoid shape.

Here is the original code I am using which gives me classical point light.
// Vertex shader
o.pos = mul (UNITY_MATRIX_MVP, float4(v,1));
o.ray = mul (UNITY_MATRIX_MV, float4(v,1)).xyz * float3(-1, -1, 1);

// Fragment
i.ray = i.ray * (_ProjectionParams.z / i.ray.z);

// read depth and reconstruct world position
depth = 1.0 / (_ZBufferParams.x * depth + _ZBufferParams.y); // Linear01Depth

float4 vpos = float4(i.ray * depth, 1);
float3 wpos = mul(unity_CameraToWorld, vpos).xyz;

float3 tolight = wpos - _LightPos.xyz;
half3 lightDir = -normalize(tolight);
// Then using the light direction to compute n.l etc...  

How could I apply the scale of the transform ? I should apply a matrix but how and where ?
I also discovered the Inside talk about transformation but I have some difficulties to apply their examples which are :

//////////////////////////////// Classic
// Vertex
vec3 viewPos = mul(modelView, objectPos);
OUT.viewRay = viewPos / viewPos.z;

// Fragment
vec3 viewPos = IN.viewRay * depth;
vec3 decalPos = mul(vec4(viewPos, 1.0), _ViewToObject);

//////////////////////////////// World Space reconstruction from Depth
// Vertex
vec3 viewPos = mul(modelView, objectPos);
vec3 viewRay = viewPos / viewPos.z;
OUT.wordRay = mul((mat3)viewToWorld, viewRay);

// Fragment
vec3 worldPos = IN.worldRay * depth + _WorldSpaceViewPos;
vec3 decalPos = mul(_WorldToObject, vec4(worldPos, 1.0));

//////////////////////////////// Object space Ray

// Vertex
vec3 viewPos = mul(modelView, objectPos);
vec3 viewRay = viewPos / viewPos.z;
OUT.objectRay = mul((mat3)_ViewToObject, viewRay);

// Fragment
vec3 decalPos = IN.objectRay * depth + _ObjectSpaceViewPos;


I am discovering deferred rendering and learning the basic but I still have some difficulties to understand the way to apply matrix and transformations that's why I would like to better understand those technics and how to apply scale.

Thanks a lot !
Edited by fire67

Share on other sites

I'm not a unity developer. But if you want some answers, you might give some more details as:

how is defined the light (position, direction, has it linear attenuation ?) ?

can you modify easily how a light is defined, so that you can make it ellipsoidal ?

The key thing here is to change your light definition so that you can calculate light shed over an ellipsoid. So you'll need to modify your light definition so that in incorporates the ellipsoid equation, and how far each of its components (maybe ambient, diffuse, specular and attenuation) behave inside this ellipsoid.

On wikipedia they have a very good paper about ellipsoids, with good mathematics functions.

Share on other sites

Thanks for your answer @_Silence_. I am using Unity but the question is not especially constrained by Unity, it's more linked with matrix and transformation but maybe I misstated my question.

Here is how the point light is calculated.

float3 tolight = wpos - _LightPos.xyz;
half3 lightDir = -normalize(tolight);

half nl = DotClamped(lightDir, normalWorld);
nl = nl * _hardness + 1.0 - _hardness; // This allows to wraps light
res.rgb = nl; // This should also be multiplied by light color and gbuffer input


But instead of having to implement an ellipsoid formula, I want to use scaling to obtain this kind of shape and this implies integrating the transform values and matrix inside the ray, world position, etc. calculations but unfortunately I don't know how to do it and I don't see where should I add this kind of transformation.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• Forum Statistics

• Total Topics
632623
• Total Posts
3007503
• Who's Online (See full list)

There are no registered users currently online

×