Jump to content

Recommended Posts

Posted

I know shader as the mix function, but it uses a fixed value we put in the shader for the percentage of mixing textures.

But it is possible to do it throught time and control it ?

 

I mean yo have some character with fire texture and with some user action like keypressed , the texture fade to another ice texture on diffuse map and on glow map.

Pressing another key , the texture would fade from ice to fire.

Stop toying and make games

Posted

Just set a uniform through code as the mix interpolation value - it doesn't have to be fixed.

 

Example shader:

mix.zip

 

Example script that shows how it works:

window = Window:Create("mix textures",0,0,800,600)

context = Context:Create(window)

world = World:Create()

camera = Camera:Create()

camera:SetPosition(0,0,-2)

light = DirectionalLight:Create()

light:SetRotation(35,35,0)

 

mixshader = Shader:Load("Shaders/Model/mix.shader")

texture0 = Texture:Load("Materials/Developer/bluegrid.tex")

texture1 = Texture:Load("Materials/Developer/leadwerks.tex")

mixmat = Material:Create()

mixmat:SetTexture(texture0,0)

mixmat:SetTexture(texture1,1)

mixmat:SetShader(mixshader)

 

box = Model:Box()

box:SetMaterial(mixmat)

 

mixture = 0.0

toggle = 0.007

 

while window:KeyDown(Key.Escape)==false do

box:Turn(0.5,0.5,0.3)

 

mixture = mixture + toggle

if mixture>=1.0 then toggle = -0.007 end

if mixture<=0.0 then toggle = 0.007 end

mixshader:SetFloat("mixture",mixture)

 

Time:Update()

world:Update()

world:Render()

context:SetBlendMode(1)

context:DrawText(string.format("Mixture: %.2f",mixture), 2 ,2)

context:SetBlendMode(0)

context:Sync(true)

end

 

Note: keep mixture value between 0.0 and 1.0

  • Upvote 3

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...