Jump to content
  • Advertisement
Sign in to follow this  
fire67

Deferred rendering and ellipsoid point light

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

If you intended to correct an error in the post then please contact us.

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
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!