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 !