RiceEatingGuy Posted June 13, 2015 Share Posted June 13, 2015 Hey, is it possible to set different textures for objects with same model id? If yes, please explain me how to do that. Thanks. Link to comment
RiceEatingGuy Posted June 13, 2015 Author Share Posted June 13, 2015 Yes, using shader Thanks. Could you explain to me how to use it or give an example? Link to comment
Walid Posted June 13, 2015 Share Posted June 13, 2015 All what you need is dxCreateTexture() dxCreateShader() dxSetShaderValue() engineApplyShaderToWorldTexture() Link to comment
RiceEatingGuy Posted June 13, 2015 Author Share Posted June 13, 2015 All what you need is dxCreateTexture() dxCreateShader() dxSetShaderValue() engineApplyShaderToWorldTexture() Well, I tried something... The problem is that it loads just one texture. client.lua addCommandHandler("toggle", function() local myShader = dxCreateShader("shader.fx") local object1 = createObject (3095, 0.0000, 0.0000, 6.0000, 90.0000, 0.0000, 0.0000) local myTexture1 = dxCreateTexture("texture1.png") dxSetShaderValue(myShader, "Tex0", myTexture1) engineApplyShaderToWorldTexture(myShader, "sam_camo", object1) local object2 = createObject (3095, 10.0000, 0.0000, 6.0000, 90.0000, 0.0000, 0.0000) local myTexture2 = dxCreateTexture("texture2.png") dxSetShaderValue(myShader, "Tex0", myTexture2) -- It doesn' t work. It loads myTexture1 engineApplyShaderToWorldTexture(myShader, "bonyrd_skin2", object2) end ) meta.xml "Author" type="script" name="Name" description="Description" /> shader.fx (copied from wiki) //----------------------------------------------------------------------- //-- Settings //----------------------------------------------------------------------- texture Tex0; //-- Replacement texture //--------------------------------------------------------------------- // Include some common stuff //--------------------------------------------------------------------- #include "mta-helper.fx" //----------------------------------------------------------------------- //-- Sampler for the new texture //----------------------------------------------------------------------- sampler Sampler0 = sampler_state { Texture = (Tex0); }; //----------------------------------------------------------------------- //-- Structure of data sent to the vertex shader //----------------------------------------------------------------------- struct VSInput { float3 Position : POSITION0; float3 Normal : NORMAL0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; //----------------------------------------------------------------------- //-- Structure of data sent to the pixel shader ( from the vertex shader ) //----------------------------------------------------------------------- struct PSInput { float4 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; //-------------------------------------------------------------------------------------------- //-- VertexShaderFunction //-- 1. Read from VS structure //-- 2. Process //-- 3. Write to PS structure //-------------------------------------------------------------------------------------------- PSInput VertexShaderFunction(VSInput VS) { PSInput PS = (PSInput)0; //-- Calculate screen pos of vertex PS.Position = mul(float4(VS.Position, 1), gWorldViewProjection); //-- Pass through tex coord PS.TexCoord = VS.TexCoord; //-- Calculate GTA lighting for buildings PS.Diffuse = MTACalcGTABuildingDiffuse( VS.Diffuse ); //-- //-- NOTE: The above line is for GTA buildings. //-- If you are replacing a vehicle texture, do this instead: //-- //-- // Calculate GTA lighting for vehicles //-- float3 WorldNormal = MTACalcWorldNormal( VS.Normal ); //-- PS.Diffuse = MTACalcGTAVehicleDiffuse( WorldNormal, VS.Diffuse ); return PS; } //-------------------------------------------------------------------------------------------- //-- PixelShaderFunction //-- 1. Read from PS structure //-- 2. Process //-- 3. Return pixel color //-------------------------------------------------------------------------------------------- float4 PixelShaderFunction(PSInput PS) : COLOR0 { //-- Get texture pixel float4 texel = tex2D(Sampler0, PS.TexCoord); //-- Apply diffuse lighting float4 finalColor = texel * PS.Diffuse; return finalColor; } //-------------------------------------------------------------------------------------------- //-- Techniques //-------------------------------------------------------------------------------------------- technique tec { pass P0 { VertexShader = compile vs_2_0 VertexShaderFunction(); PixelShader = compile ps_2_0 PixelShaderFunction(); } } //-- Fallback technique fallback { pass P0 { //-- Replace texture Texture[0] = Tex0; //-- Leave the rest of the states to the default settings } } I also downloaded mta-helper.fx Link to comment
Ren_712 Posted June 13, 2015 Share Posted June 13, 2015 Hey,is it possible to set different textures for objects with same model id? If yes, please explain me how to do that. Thanks. lua: local myobject = createObject ( ... local myshader = dxCreateShader("effect_file.fx") local mytexture = dxCreateTexture("mytexture.png", "dxt5") dxSetShaderValue( myshader,"gTexture", mytexture) engineApplyShaderToWorldTexture( shader, "texturename", myobject ) effect: texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } Link to comment
RiceEatingGuy Posted June 13, 2015 Author Share Posted June 13, 2015 Hey,is it possible to set different textures for objects with same model id? If yes, please explain me how to do that. Thanks. lua: local myobject = createObject ( ... local myshader = dxCreateShader("effect_file.fx") local mytexture = dxCreateTexture("mytexture.png", "dxt5") dxSetShaderValue( myshader,"gTexture", mytexture) engineApplyShaderToWorldTexture( shader, "texturename", myobject ) effect: texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } Thanks, but how to apply two different textures to two objects? I get same texture on both objects. Link to comment
Ren_712 Posted June 14, 2015 Share Posted June 14, 2015 I get same texture on both objects. That means you did not apply the shader to the 'object' element. 'object' can be a vehicle, ped, world object. For example: You create 2 objects 2 shaders and 2 textures dxSetShaderValue( myshader1,"gTexture", mytexture1) dxSetShaderValue( myshader2,"gTexture", mytexture2) engineApplyShaderToWorldTexture( shader1, "texturename", myobject1 ) engineApplyShaderToWorldTexture( shader2, "texturename", myobject2 ) Link to comment
Walid Posted June 14, 2015 Share Posted June 14, 2015 You don't need to create 2 objects 2 shaders and 2 textures, simply you can use tables. Example: Objects = { {model = ,x = ,y = , z = ,rx = ,ry = , rz = ,tex = "Texture name here" }, } for i , v in pairs (Objects) do -- Your code her end Link to comment
RiceEatingGuy Posted June 14, 2015 Author Share Posted June 14, 2015 EDIT: I think I fixed it. Do you see any mistakes or have any advices? objects = { {model = 3095, x = 0.0000, y = 0.0000, z = 6.0000, rx = 90.0000, ry = 0.0000 , rz = 0.0000, tex = "texture1.png", worldtex = "sam_camo"}, {model = 3095, x = 10.0000, y = 0.0000, z = 6.0000, rx = 90.0000, ry = 0.0000 , rz = 0.0000, tex = "texture2.png", worldtex = "bonyrd_skin2"} } addCommandHandler("toggle", function() for i, v in pairs (objects) do object = createObject(objects[i].model, objects[i].x, objects[i].y, objects[i].z, objects[i].rx, objects[i].ry, objects[i].rz, false) myShader = dxCreateShader("shader.fx") myTexture = dxCreateTexture(objects[i].tex, "dxt5") dxSetShaderValue(myShader, "gTexture", myTexture) engineApplyShaderToWorldTexture(myShader, objects[i].worldtex, object) end end ) OLD: You don't need to create 2 objects 2 shaders and 2 textures, simply you can use tables.Example: Objects = { {model = ,x = ,y = , z = ,rx = ,ry = , rz = ,tex = "Texture name here" }, } for i , v in pairs (Objects) do -- Your code her end objects = { {model = 3095, x = 0.0000, y = 0.0000, z = 6.0000, rx = 90.0000, ry = 0.0000 , rz = 0.0000}, {model = 3095, x = 10.0000, y = 0.0000, z = 6.0000, rx = 90.0000, ry = 0.0000 , rz = 0.0000} } addCommandHandler("toggle", function() for i, v in pairs (objects) do object = createObject(model, x, y, z, rx, ry, rz, false) end end ) Thanks, but I don' t really get it. What' s wrong with createObject script? I tried it in many other ways, but that doesn' t work. Link to comment
Walid Posted June 14, 2015 Share Posted June 14, 2015 Wrong it should be like this objects = { {model = 3095, x = 0, y = 0, z = 6, rx = 90, ry = 0 , rz = 0, tex = "texture name here"}, {model = 3095, x = 10, y = 0, z = 6, rx = 90, ry = 0 , rz = 0, tex = "texture name here"} } addCommandHandler("toggle", function() for i, v in pairs (objects) do local object = createObject(v.model,v.x,v.y,v.z,v.xr,v.xy,v.xz) -- Your code here end end ) Link to comment
RiceEatingGuy Posted June 14, 2015 Author Share Posted June 14, 2015 Wrong it should be like this objects = { {model = 3095, x = 0, y = 0, z = 6, rx = 90, ry = 0 , rz = 0, tex = "texture name here"}, {model = 3095, x = 10, y = 0, z = 6, rx = 90, ry = 0 , rz = 0, tex = "texture name here"} } addCommandHandler("toggle", function() for i, v in pairs (objects) do local object = createObject(v.model,v.x,v.y,v.z,v.xr,v.xy,v.xz) -- Your code here end end ) Oh... Thanks. EDIT: Is it possible to make something like this (two textures): objects = { {..., worldtex = "sam_camo" and "bonyrd_skin2", tex = "texture1.png" and "texture3.png"}, {..., worldtex = "bonyrd_skin2" and "sam_camo", tex = "texture2.png" and "texture4.png"} } OLD: Does it make sense if coordinates are like this: objects = { {x = 0, y = 0, z = 6, rx = 90, ry = 0 , rz = 0}, {x = 10, y = 0, z = 6, rx = 90, ry = 0 , rz = 0} } or this: objects = { {x = 0.0000, y = 0.0000, z = 6.0000, rx = 90.0000, ry = 0.0000, rz = 0.0000}, {x = 10.0000, y = 0.0000, z = 6.0000, rx = 90.0000, ry = 0.0000, rz = 0.0000} } ? I also think that you made mistake here: local object = createObject(..., v.xr,v.xy,v.xz) Shouldn' t it be like this? local object = createObject(..., v.rx, v.ry, v.rz) Anyways, thanks everyone. Link to comment
Walid Posted June 14, 2015 Share Posted June 14, 2015 1) About the first question it's not posible , maybe you can use table inside the main table like this local table = { {..., worldtex = {"sam_camo" ,"bonyrd_skin2"}, tex = {"texture1.png","texture3.png"}} } 2) About second question both are correct. 3) The last question i just gave you an example you can fix it by yourself later. 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