GLSL to HLSL translate.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

GLSL to HLSL translate.

Post by Vsk »

Someone please could pass this glsl code to hlsl code equivalent?
It should be a minute for an expert but is russian for me.

Code: Select all

uniform sampler2D Texture;

varying vec4 Color;

void main()
{
	gl_FragColor = texture2D( Texture, gl_TexCoord[0].xy ) * Color;
}

Code: Select all

varying vec4 Color;

void main()
{
	Color = gl_Color;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();
}
Thanks
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

This is fully untested, so theres probably a spelling mistake or something in there:

Code: Select all

float4x4 mWorldViewProj;

struct a2v 
{ 
    float4 Position : POSITION;
    float2 Texcoords : TEXCOORD0; 
    float4 Color     : COLOR0;
};

struct v2p 
{
    float4 Position  : POSITION;
    float2 Texcoords  : TEXCOORD0;
    float4 Color     : COLOR0;
};


void vertexMain( in a2v IN, out v2p OUT ) 
{
OUT.Position = mul(IN.Position, mWorldViewProj);
OUT.Color = IN.Color;
OUT.Texcoords = IN.Texcoords;
}

sampler Texture  : register(s0); 

float4 pixelMain(in v2p IN) : COLOR0 
{
return tex2D(Texture , IN.Texcoords) * IN.Color;
}
IMPORTANT:
For this, you have to pass the WorldViewProj "mWorldViewProj" matrix to the shader as a shader constant, this is done in the shader example in the Irrlicht SDK, so just do what they did there. Also, you don't have to pass the texture name as a constant in GLSL so take that out of the constant callback.

Btw, this shader doesn't really do anything, you might as well just use fixed-function.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Just curious about the:

Code: Select all

sampler Texture : register(s0);
Can you assign texture samplers to a register in GLSL?
TheQuestion = 2B || !2B
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, it's automatically assigned to the uniform samplers, if not explicitly bound to them.
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

Hi, thanks, I will try it.
This code isn't mine is Klasker's code, from the procedural tres.
There is no version of this shaders for direct x.

Thanks again.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

hybrid wrote:No, it's automatically assigned to the uniform samplers, if not explicitly bound to them.
When did this happen? Last time I checked you had to explicitly define them using uniform variables yourself.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, you can assign textures to uniform samplers as you want, but the currently bound textures are otherwise assigned to your samplers AFAIK, as part of OpenGL behavior.
Post Reply