Dzsozi (h03) Posted June 22, 2017 Share Posted June 22, 2017 Hello! This is my first time working with shaders and I bumped into a problem. I would like to define two textures in one shader file, so I need less coding in lua and don't have to create the shader two times. I want to make a back-up light system for vehicles and I want to reach that by changing the vehiclelights128 and vehiclelightson128 textures. Since these are two different textures, I must replace them both when backing up with a car, since I can't detect if the lights are on or off if the setVehicleOverrideLights is set to 0 (default, changing automatically). That's why I would like to create something like onTexture and offTexture inside the shader file, but I don't know how can I do that, since I have never worked with shaders before. I tried something like this, but this doesn't work: Shader file: texture onTexture; texture offTexture; technique hello { pass P0 { Texture[0] = onTexture; Texture[1] = offTexture; } } I don't know how I should do this. And the lua file (only a part of it, the backing mechanism and everything works): if not shaderReverse and seat == 0 then shaderReverse = dxCreateShader ( "files/texture.fx" ) textureReverse = dxCreateTexture ( "files/images/vehiclelightsreverse128.png", "dxt5" ) textureReverseOn = dxCreateTexture ( "files/images/vehiclelightsonreverse128.png", "dxt5" ) end if shaderReverse then engineRemoveShaderFromWorldTexture ( shaderReverse, "vehiclelights128", vehicle ) engineRemoveShaderFromWorldTexture ( shaderReverse, "vehiclelightson128", vehicle ) end if engine then if getControlState("brake_reverse") and gear == 0 and getVehicleSpeed(vehicle) > 0 then dxSetShaderValue ( shaderReverse, "onTexture", textureReverseOn ) engineApplyShaderToWorldTexture ( shaderReverse, "vehiclelightson128", vehicle ) dxSetShaderValue ( shaderReverse, "offTexture", textureReverse ) engineApplyShaderToWorldTexture ( shaderReverse, "vehiclelights128", vehicle ) end end So what doesn't work: the textures get replaced immediately on resource start, it worked when I did it with one texture in the shader file, but then I couldn't change the vehiclelightson128 texture, that's why I want to "define" two textures in the shader file. Hope you understand me. Thank you for your help in advance! 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