Jump to content

Different texture for every object using shaders.


quindo

Recommended Posts

Hello everyone, I've implemented a improvised bump map shader, that uses a normal map texture of an object. The thing is that every object needs to have custom texture, so 1 texture for 1 object, as for now i know only how to use it for single object. I can't just use engineApplyShaderToWorldTexture(shader,"*"), because it applies the same texture to every object. How can i make it use different textures for different objects? Here's current example showing the difference that the shader makes(open in 2 tabs and compare them):

http://i.imgur.com/BWYPR5Y.jpg

http://i.imgur.com/t7Yvsmr.jpg

Link to comment

Okay, sorry, i guess it was written in a bit of a rush. The thing is that i created the shader that applies bump map to custom object (the rocks in my first 2 screenshots), the original texture is mixed with the normal map (screenshot in my last reply). The shader takes the normal as a Value like this:

        normal = dxCreateTexture("normal/kamienie_nororg.jpg") 
        dxSetShaderValue(shader,"Tex0",normal) 
        engineApplyShaderToWorldTexture(shader,"kamienie") 

I want to use the same shader for more than 1 object, which means that i need to give every object it's custom texture. I'm looking for the best way to do it.

Link to comment

Use a table to define the textures, then define the shader with local and set the local shaders value, then apply it. If that makes sense.

  
textures = {{"texturename","Something.png"},{"texturename2","Something2.png"}} 
  
for i,v in pairs (texutres) do 
local shader = dxCreateShader( "whatever.fx" ) 
local normal = dxCreateTexture("normal/"..v[2]) 
dxSetShaderValue(shader,"Tex0",normal) 
engineApplyShaderToWorldTexture(shader,v[1]) 
end 

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...