Xeon06 Posted May 29, 2012 Share Posted May 29, 2012 Hey all, I'm trying to change the color of the seats in the police cars using shaders. I took the example from the wiki, fixed a few errors and removed the part that modifies the colors. This resulted in the seats (and the lightbar because it's in the same texture) being pitch black. After a little debugging I noticed that if I commented out the line that multiplies the value by the diffuse in the pixel shader, the seat and lightbar are rendered in full bright. The problem would then be that the diffuse value I am getting is empty. Here is my code: addEventHandler("onClientResourceStart", getRootElement(), function() local shader, tech = dxCreateShader("test.fx") if not shader then outputChatBox("Could not create shader. Please use debugscript 3") else outputChatBox("Using technique " .. tech) local tex = dxCreateTexture("copcarla92interior128.png"); dxSetShaderValue(shader, "Tex0", tex); engineApplyShaderToWorldTexture(shader, "copcarla92interior128") end end ) texture Tex0; float4x4 World; float4x4 View; float4x4 Projection; float4x4 WorldViewProjection; float Time; sampler Sampler0 = sampler_state { Texture = (Tex0); }; struct VSInput { float4 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; struct PSInput { float4 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; PSInput VertexShaderExample(VSInput VS) { PSInput PS = (PSInput)0; PS.Position = mul(VS.Position, WorldViewProjection); PS.Diffuse = VS.Diffuse; PS.TexCoord = VS.TexCoord; return PS; } float4 PixelShaderExample(PSInput PS) : COLOR0 { float4 finalColor = tex2D(Sampler0, PS.TexCoord); //finalColor = finalColor * PS.Diffuse; //Commenting this line shows the texture in full bright return finalColor; } technique complex { pass P0 { VertexShader = compile vs_2_0 VertexShaderExample(); PixelShader = compile ps_2_0 PixelShaderExample(); } } technique simple { pass P0 { Texture[0] = Tex0; ColorOp[0] = SelectArg1; ColorArg1[0] = Texture; AlphaOp[0] = SelectArg1; AlphaArg1[0] = Texture; ColorOp[1] = Disable; AlphaOp[1] = Disable; } } Does anyone know what's up with the diffuse value? Am I doing something wrong? For some reason, it stays at 0. Thanks. Link to comment
Al3grab Posted May 30, 2012 Share Posted May 30, 2012 I don't know much about shaders but the event should be like this addEventHandler("onClientResourceStart", resourceRoot, function() -- reseourceRoot = getResourceRootElement(getThisResource()) Link to comment
MTA Team ccw Posted May 30, 2012 MTA Team Share Posted May 30, 2012 I've updated the shaders page on the wiki to include an example of diffuse lighting: https://wiki.multitheftauto.com/wiki/Ele ... d_textures Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now