BBC BASIC for Windows
« D3D11 Pixel Shader »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:54pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: D3D11 Pixel Shader  (Read 105 times)
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx D3D11 Pixel Shader
« Thread started on: Dec 23rd, 2017, 10:06pm »

Posted this on the other forum and Richard advised me that this forum would be a better place to post. So here goes.
Code:
cbuffer ConstantBuffer : register( b0 )
{
	matrix World;
	matrix View;
	matrix Projection;
	float4 vLightDir;
	float4 vLightColor;
	float4 ambient;
	//float4 vOutputColor;
}

//--------------------------------------------------------------------------------------
struct VS_INPUT
{
    float4 Pos : POSITION;
	float3 Norm : NORMAL; 
	float4 Color : COLOR;
};

struct PS_INPUT
{
    float4 Pos : SV_POSITION;
	float3 Norm : TEXCOORD0;
	float4 Color : COLOR;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
	float4 normal;
	float4 diffuseColor = 0;
	
	PS_INPUT output = (PS_INPUT)0;
    output.Pos = mul( input.Pos, World );
    output.Pos = mul( output.Pos, View );
    output.Pos = mul( output.Pos, Projection );

	normal = mul(input.Norm, World);
	diffuseColor += dot((float3)vLightDir, normal);
	diffuseColor += 1;
	diffuseColor /= 2;
	diffuseColor * (1 - ambient);
	diffuseColor *= input.Color;
	diffuseColor += ambient;
	output.Color = diffuseColor * vLightColor;
	
return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input) : SV_Target
{
	
return input.Color;
}
 

I have managed to convert the vertex shader to sensible light effect, but no matter what I do the pixel shader returns a fault. I woud like to be able to use color.alpha to affect the other 3 components (why are they x,y,x,w and not r,g,b,a?), if I use input.color.w, or just input.color it fails, WHY?

I have modified the simple vertex to
Code:
 DIM SimpleVertex{Pos{}=XMFLOAT3{},Normal{}=XMFLOAT3{},Color{}=XMFLOAT4{}}

      DIM layout{(2)} = D3D11_INPUT_ELEMENT_DESC{}
      sn0$ = "POSITION" + CHR$(0)
      layout{(0)}.SemanticName% = !^sn0$
      layout{(0)}.Format% = DXGI_FORMAT_R32G32B32_FLOAT
      layout{(0)}.AlignedByteOffset% = 0
      layout{(0)}.InputSlotClass% = D3D11_INPUT_PER_VERTEX_DATA
      sn1$ = "NORMAL" + CHR$(0)
      layout{(1)}.SemanticName% = !^sn1$
      layout{(1)}.Format% = DXGI_FORMAT_R32G32B32_FLOAT
      layout{(1)}.AlignedByteOffset% = 12
      layout{(1)}.InputSlotClass% = D3D11_INPUT_PER_VERTEX_DATA
      sn2$ = "COLOR" + CHR$(0)
      layout{(2)}.SemanticName% = !^sn2$
      layout{(2)}.Format% = DXGI_FORMAT_R32G32B32A32_FLOAT
      layout{(2)}.AlignedByteOffset% = 24
      layout{(2)}.InputSlotClass% = D3D11_INPUT_PER_VERTEX_DATA
      numElements% = DIM(layout{()},1) + 1
  


Can anybody help?

Richard eluded to possible help from Michael Hutton, can you help Michael?

Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: D3D11 Pixel Shader
« Reply #1 on: Dec 24th, 2017, 11:07pm »

I'm sorry I can't help, but I hope someone else can.

I would be surprised if you hear from Michael Hutton on this forum because he left the BB4W 'scene' a few years ago, which was quite a loss for some of us. I don't know if he still monitors this forum at all, perhaps on an occasional basis. Last time I heard he had migrated over to PureBasic.


David.
--
User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: D3D11 Pixel Shader
« Reply #2 on: Dec 25th, 2017, 09:54am »

Thanks David, this could be a blow to using d3d11! I was hoping to change my 3d object project to d3d but maybe not yet.

Regards Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls