how can I use multiple textures in hxsl

59 views
Skip to first unread message

davy zhang

unread,
Mar 11, 2014, 2:52:15 AM3/11/14
to haxe...@googlegroups.com
hxsl2

I write fragment func like this
function fragment(tex0:Texture, tex1:Texture, tex2:Texture, tex3:Texture) 

but the problem is I don't the exact number of textures will used here

currently I uploaded 8 tex with some empty bitmapdata textures

but in agal I can dynamically make the agal opcode string to achieve this
for (var x:int;i < textureCount;i++){
 "tex " + ftColor + "," +  + "," + fsList[i] + "<2d,repeat,miplinear,linear>", 
}

how can I do this in hxsl?

thanks

David Elahee

unread,
Mar 11, 2014, 2:59:10 AM3/11/14
to haxe...@googlegroups.com

I dont think its possible with hxsl2 dunno for 3.

Btw i think you should fallback to cubemap or texture 3d rather than heavy texture multi maps.. 8 map or so is fairly unusual for a single pass and will cost you your soul or something approaching .

What are you trying to achieve my friend ?

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

davy zhang

unread,
Mar 11, 2014, 3:08:31 AM3/11/14
to haxe...@googlegroups.com
Well, here is the situation.

I have a model with multiple meshes and different textures, some of the textures used repeat mode to map the texture,
so ,it's not possible to merge them into one bitmap like cubemap or manually 

all I wish to do is to draw this model in one draw call.

I've tested for stage3d with agal, multiple draw call cost much more than fs register sample usage in this situation

David Elahee

unread,
Mar 11, 2014, 3:15:22 AM3/11/14
to haxe...@googlegroups.com

Gpu have a hardcoded max_texture_unit so i think it is not safe to go beyond 8.

Also if the mesh is already ready it shouldnt be that slower to draw, you have to share the shader manually and maybe improve the st3d driver if it perform redundant state changes.

Is is that slow ? Are you benching in debug  ?

Dont Forget to render back to front to profit the z buffer.

How many vertices are you sending to gpu ?

Good luck.

davy zhang

unread,
Mar 11, 2014, 3:22:07 AM3/11/14
to haxe...@googlegroups.com
Thanks for the reply

I am not gonna  go beyond 8, actually I am using less than 8 fs register

Let me explain a little bit clear

I have model with mutliple textures and meshes, all of the textures are mapped using repeat mode.
so I have 2 choices to draw this model
1. draw multiple times, one time with one mesh
2. draw one time, with all the textures (assume it lesser than 8)

here I am talking about the 2nd choice
here is the basic trick
I gonna read all the tex in fs1..8
sample each of them using the given uv coordinate, but obviously only one of the color is right
so I compare the idx data using eq to get 1 / 0 result 
multiple the result to each sampled color

I get the right color and out put it

David Elahee

unread,
Mar 11, 2014, 3:28:11 AM3/11/14
to haxe...@googlegroups.com

Ok keep us posted , the h3d light system has arrays for lights maybe you can adapt the mechanic for your texture ids. ++

davy zhang

unread,
Mar 11, 2014, 3:57:37 AM3/11/14
to haxe...@googlegroups.com
BTW: I am not the only one using this trick for batch draw:)

here's the blog from Genome2D author


I know this not possible in hxsl right now and I can upload empty bd to workaround

I'll try to file an issue for this

David Elahee

unread,
Mar 11, 2014, 4:01:39 AM3/11/14
to haxe...@googlegroups.com

I am not super fond of the technique as its pixel shader intensive which is quite shitty for mobile and non desktop but i recognize it powerful though :)

Reply all
Reply to author
Forward
0 new messages