Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:05:56+00:00 2026-06-16T10:05:56+00:00

Im trying to set up deferred renderer using ogre compositor framework. I tried to

  • 0

Im trying to set up deferred renderer using ogre compositor framework. I tried to implement a point-light shader (as a fullscreen quad effect, without attenuation or specular calculations) in the code below:

Material that outputs deferred data to GBuffer:

void ToGBufferVP
                (
                    float4 iPosition : POSITION,
                    float3 iNormal : NORMAL,
                    float2 iUV0 : TEXCOORD,

                    out float4 oPosition : POSITION,
                    out float3 oViewPos : TEXCOORD0,
                    out float3 oNormal : TEXCOORD1,
                    out float2 oUV0 : TEXCOORD2,

                    uniform float4x4 cWorldViewProj,
                    uniform float4x4 cWorldView
                )
{
    oPosition = mul(cWorldViewProj, iPosition);
    oNormal = mul(cWorldView, float4(iNormal,0)).xyz;
    oViewPos = mul(cWorldView, iPosition).xyz;
    oUV0 = iUV0;
}

void ToGBufferFP
                (
                    float3 iViewPos : TEXCOORD0,
                    float3 iNormal : TEXCOORD1,
                    float2 iUV0 : TEXCOORD2,

                    out float4 oColor0 : COLOR0,
                    out float4 oColor1 : COLOR1,

                    uniform sampler2D sTex : register(s0),
                    uniform sampler2D sSpec : register(s1),

                    uniform float cFarDistance
                )
{
    oColor0.rgb = tex2D(sTex, iUV0);
    oColor0.a = tex2D(sSpec, iUV0);
    oColor1.rgb = normalize(iNormal);
    oColor1.a = length(iViewPos) / cFarDistance;
}

Vertex program description:

vertex_program ScreenQuadDebugLight_VS cg
{
    source MyDeferredPostShader.hlsl
    profiles vs_1_1 arbvp1
    entry_point ScreenQuadDebugLight_VS

    default_params
    {
        param_named_auto worldViewProj worldviewproj_matrix
    }
}

Fragment program description:

fragment_program ScreenQuadDebugLight_PS cg
{
    source MyDeferredPostShader.hlsl
    profiles ps_2_0 arbfp1
    entry_point ScreenQuadDebugLight_PS

    default_params
    {
        param_named_auto vpWidth viewport_width
        param_named_auto vpHeight viewport_height       

        param_named_auto flip render_target_flipping
        param_named_auto farClipDistance far_clip_distance

        param_named_auto lightPos light_position_view_space 0
    }
}

Light material script:

material DeferredShadingPostQuadLight
{
    technique
    {
        pass
        {
            cull_hardware none
            cull_software none

            depth_func always_pass

            vertex_program_ref ScreenQuadDebugLight_VS
            {
            }

            fragment_program_ref ScreenQuadDebugLight_PS
            {
            }

            texture_unit
            {
                tex_coord_set 0
                tex_address_mode clamp
                filtering none
            }

            texture_unit
            {
                tex_coord_set 1
                tex_address_mode clamp
                filtering none
            }
        }
    }
}

Light shader:

void ScreenQuadDebugLight_VS
    (
        float4 Pos: POSITION,   
        out float4 oPos: POSITION,
        out float4 oTexCoord : TEXCOORD0,   
        uniform float4x4 worldViewProj
    )
{
    float4 projPos = mul(worldViewProj, Pos);
    oTexCoord = projPos;    
    oPos = projPos;
}

float4 ScreenQuadDebugLight_PS
    (
        float4 projPos : TEXCOORD0,
        uniform sampler Tex0: register(s0),
        uniform sampler Tex1: register(s1),

        uniform float vpWidth,
        uniform float vpHeight,

        uniform float flip,
        uniform float farClipDistance,

        uniform float3 lightPos
    ) : COLOR 
{
    // Get homogenous coordinates
    projPos.xy /= projPos.w;

    // Compensate texture coordinate half pixel jitter
    float2 texCoord = 0.5f * (float2(projPos.x, -projPos.y) + 1);
    float2 halfPixel = float2(0.5/vpWidth, 0.5/vpHeight);
    texCoord += halfPixel;

    float3 ray = float3(projPos.x, projPos.y * flip, 1);

    float4 a0 = tex2D(Tex0, texCoord); // Albedo and Specularity
    float4 a1 = tex2D(Tex1, texCoord); // Normal and Depth

    // Attributes
    float3 colour = a0.rgb;
    float specularity = a0.a;
    float distance = a1.w;
    float3 normal = a1.xyz;

    float3 viewPos = normalize(ray);
    viewPos.z = distance;

    float3 objToLightVec =  lightPos - viewPos;
    float len_sq = dot(objToLightVec, objToLightVec);
    float len = sqrt(len_sq);
    float3 objToLightDir = normalize(objToLightVec);

    float3 total_light_contrib;
    total_light_contrib = max(0.0, dot(objToLightDir, normal));

    return float4(total_light_contrib, 0.0);
}

This is how i declare light in my .cpp file:

lLightSceneNodeHolder = mSceneMgr->getRootSceneNode()->createChildSceneNode();

Ogre::Light *light;
light = mSceneMgr->createLight();
light->setType(Ogre::Light::LT_POINT);
light->setPosition(Ogre::Vector3(0, 0, -0.7f));
light->setVisible(true);
light->setDiffuseColour(Ogre::ColourValue::White);
light->setSpecularColour(Ogre::ColourValue::White);
lLightSceneNodeHolder->attachObject(light);

I get the output and everything works fine – except i cant get lighting to work correctly. G Buffer contains valid data – view-space normals, linear z-depth, textures. I also get light position in view space as a parameter – however there are some problems during vector calculations – and the output is nothing like point light should be. What am i doing wrong here?

Thanks!

P.S. I also tried to pass lightPos parameter manually, via compositor listener, but then the light looked more like a directional light…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:05:57+00:00Added an answer on June 16, 2026 at 10:05 am

    The problem was in the equation:

    float3 ray = float3(projPos.x, projPos.y * flip, 1);

    It had to be multiplied by farCorner value, which is far corner of the camera frustum:

    float3 ray = float3(projPos.x, projPos.y * flip, 1) * farCorner;

    You can get it by using

    mCamera->getWorldSpaceCorners()[1];

    and then plugging it in the compositor listener like this:

    void LightListener::notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
    {
        vpParams = mat->getBestTechnique()->getPass(0)->getVertexProgramParameters();
        fpParams = mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
    }
    
    void LightListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
    {
        vpParams->setNamedConstant("lightPos", lightPos);
        fpParams->setNamedConstant("farCorner", mCamera->getWorldSpaceCorners()[1]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to implement deferred shading using Ogre 1.8. This is my final compositor:
Trying to set up an extension method in .Net 3.0 using generics and I
Trying to set up the svn commit with trac using this script. It is
Trying to set up facebook authentication using devise, omniauth (including facebook-omniauth) on an app
Trying to set up the UI using Netbeans' visual UI builder, but I want
Hello everyone I'm currently trying to create a deferred renderer for my graphics engine
I am trying to set an oauth2 provider up using up on an application
Trying to set up a new site using MVC RC4 web API in Visual
Trying to set up caching on our datasets - we're using clr stored procedures
Trying to set window.location or using window.navigate() to make the browser go to about:crash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.