Skip to main content
GameDev.net gamedev.net
🔒 Locked

SharpDX Load bmp and send to pixel shader to sample it

Started by bogdan7 Sep 15, 2021 at 2:31 AM 0 replies 4.6k views
Original Post
bogdan7
bogdan7

I have a bmp and I want to texture a mesh with it.I calculated the uvs for the mesh and sent them to vertex shader.I have no idea how to take the data from.bmp file and send it to pixel shader.

Bitmap bitmap = new Bitmap(texturePath);

The vertexShader.hlsl:

#pragma pack_matrix( row_major )
cbuffer const_buffer : register(b0) {
float4x4 object;
float4x4 view;
float4x4 proj;

};

struct VS_INPUT {
	float3 pos : POSITION;
	float2 uvs : TEXCOORD0;

};
struct VS_OUTPUT { //PS_INPUT
	float4 pos : SV_POSITION;
	float2 uvs : TEXCOORD0;

};
VS_OUTPUT main(VS_INPUT input)
{
	VS_OUTPUT output;
	float4x4 OVP = mul(mul(object, view), proj);
	float4 position = float4(input.pos, 1);


	output.uvs = input.uvs;
	output.pos = mul(position, OVP);


	return output;
}

The pixelShader.hlsl:

Texture2D texture0; //how to receive the bmp here?
SamplerState SampleType;

struct PS_INPUT { //VS_OUTPUT
	float4 pos : SV_POSITION;
	float2 uvs : TEXCOORD0;
	
};
struct PS_OUTPUT {
	float4 color : SV_TARGET;

};


PS_OUTPUT main(PS_INPUT input)
{
	PS_OUTPUT output;
	output.color = texture0.Sample(SampleType, input.uvs);
	return output;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.