Jump to content

[HELP] Ren712 Object-Preview shader apply problems


Rolplay

Recommended Posts

Hi! I use @Ren_712's object-viewer resource for my cars, and i have a problem with using shaders. I want to apply a light shader to the car, which turns on only the vehiclelights128 texture without the lights.

Here is my shader: 

#include "mta-helper.fx"

float gMultiplier = 0;

sampler Sampler0 = sampler_state
{
    Texture         = (gTexture0);
    MinFilter = Linear;
	MagFilter = Linear;
};


struct VSInput
{
  float3 Position : POSITION0;
  float2 TexCoord : TEXCOORD0;
};

struct PSInput
{
  float4 Position : POSITION0;
  float2 TexCoord : TEXCOORD0;
};

PSInput VertexShaderFunction(VSInput VS)
{
    PSInput PS = (PSInput)0;

    PS.Position = MTACalcScreenPosition ( VS.Position );
    PS.TexCoord = VS.TexCoord;

    return PS;
}

float4 PixelShaderFunction(PSInput PS) : COLOR0
{
    float4 color = tex2D(Sampler0, PS.TexCoord);
    color = color*gMultiplier;

    return color;
}

technique tec0
{
    pass P0
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

And here is my client script, which turn on the light. 

local animShads = {}
local lights = 0



    function updateLights(myElementRT2)
        
        if lights == 0 then
            setVehicleOverrideLights( myElementRT2, 1 )
            
            if animShads[myElementRT2] then
                destroyElement(animShads[myElementRT2][1])
                animShads[myElementRT2] = nil

            end
        elseif lights == 1 then
            local shad = dxCreateShader("shader2.fx")
            
            animShads[myElementRT2] = {shad,0}
            iprint(animShads)
            engineApplyShaderToWorldTexture( shad, tex_reverse, myElementRT2)

        end
    end
    
    local last = 0
    
    function updateMultipliers()
        local cur = getTickCount()-last

        last = getTickCount()
        for k,v in pairs(animShads) do
            --iprint(v[2])
            v[2] = v[2] + cur/1000
            dxSetShaderValue(v[1],"gMultiplier",v[2])
            if v[2] >= 1 then
                destroyElement(v[1])
                setVehicleOverrideLights(k, 2 )
                setVehicleHeadLightColor(k,0,0,0)
                animShads[k] = nil
                --setVehicleHeadLightColor(veh,0,0,0)
            end
        end
    end
    addEventHandler("onClientRender",root,updateMultipliers)
            if myElement then


                        if lights == 0 then
                        lights = 1

                        elseif lights == 1 then
                        lights = 0
                        else
                        lights = 0
                        
                        end
                        local myElementRT = exports.object_preview:getRenderTarget()
                        iprint(myElementRT)
                        updateLights(myElementRT)
                        end
                end

PS.: I think this is not the script's fault because its work fine with normal cars which spawned on world.

Edited by Rolplay
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...