Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmrheisenberg

Posted 11 September 2012 - 11:28 AM

I get error X3018: invalid subscript 'xyz' when I try to compile my vertex shader.Here is my shader code:

cbuffer PerFrameConstants : register(b0)
{
	float4x4 worldViewProjectionMatrix;
	float4x4 worldViewMatrix;
	float4x4 viewProjectionMatrix;
	float4x4 projectionMatrix;
	float4 cameraNearFar;
	uint4 framebufferDimensions;
	float tessellationFactor;
	float3 padding;
};

struct GeometryVSIn
{
	float3 position : position;
	float3 normal   : normal;
	float2 texCoord : texCoord;
	float3 instancePosition : instancePosition;
	float3 instanceRotation : instanceRotation;
};
struct GeometryVSOut
{
	float4 position	 : SV_Position;
	float3 positionView : positionView;
	float3 normal	   : normal;
	float2 texCoord	 : texCoord;
};


float4x4 RotateV2M(float3 rotation)
{
float4x4 rotateX = { 1.0f, 0.0f, 0.0f, 0.0f,
							   0.0f, cos(rotation.x), -sin(rotation.x), 0.0f,
							   0.0f, sin(rotation.x), cos(rotation.x), 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f  };
float4x4 rotateY = { cos(rotation.y), 0.0, sin(rotation.y), 0.0f,
							   0.0f, 1.0f, 0.0f, 0.0f,
							   -sin(rotation.y), 0.0, cos(rotation.y), 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f   };
float4x4 rotateZ = { cos(rotation.z), -sin(rotation.z), 0.0f, 0.0f,
							   sin(rotation.z), cos(rotation.z), 0.0f, 0.0f,
							   0.0f, 0.0f, 1.0f, 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f   };
return mul(rotateY, mul(rotateX, rotateZ));
}

GeometryVSOut GeometryVS(GeometryVSIn input)
{
	GeometryVSOut output;
	output.position.x += input.instancePosition.x;
	output.position.y += input.instancePosition.y;
	output.position.z += input.instancePosition.z;
float4x4 rotationMatrix = RotateV2M(input.instanceRotation);
	output.position	 = mul(float4(input.position, 1.0f), mul(worldViewProjectionMatrix, rotationMatrix));
	output.positionView = mul(float4(input.position, 1.0f), mul(worldViewMatrix, rotationMatrix).xyz;
	output.normal	   = mul(float4(input.normal, 0.0f), mul(worldViewMatrix, rotationMatrix)).xyz;
	output.texCoord	 = input.texCoord;
  
	return output;
}





So the problem is in the last function(the main vertex shader one),it somehow has trouble converting from float3 to float4 I think,I'm actualy new to the .xyz functionality,I think it's called swizzling.Maybe I'm not implementing the swizzling properly?

#2mrheisenberg

Posted 11 September 2012 - 11:26 AM

I get error X3018: invalid subscript 'xyz' when I try to compile my vertex shader.Here is my shader code:

cbuffer PerFrameConstants : register(b0)
{
	float4x4 worldViewProjectionMatrix;
	float4x4 worldViewMatrix;
	float4x4 viewProjectionMatrix;
	float4x4 projectionMatrix;
	float4 cameraNearFar;
	uint4 framebufferDimensions;
	float tessellationFactor;
	float3 padding;
};

struct GeometryVSIn
{
	float3 position : position;
	float3 normal   : normal;
	float2 texCoord : texCoord;
	float3 instancePosition : instancePosition;
	float3 instanceRotation : instanceRotation;
};
struct GeometryVSOut
{
	float4 position	 : SV_Position;
	float3 positionView : positionView;
	float3 normal	   : normal;
	float2 texCoord	 : texCoord;
};


float4x4 RotateV2M(float3 rotation)
{
float4x4 rotateX = { 1.0f, 0.0f, 0.0f, 0.0f,
							   0.0f, cos(rotation.x), -sin(rotation.x), 0.0f,
							   0.0f, sin(rotation.x), cos(rotation.x), 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f  };
float4x4 rotateY = { cos(rotation.y), 0.0, sin(rotation.y), 0.0f,
							   0.0f, 1.0f, 0.0f, 0.0f,
							   -sin(rotation.y), 0.0, cos(rotation.y), 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f   };
float4x4 rotateZ = { cos(rotation.z), -sin(rotation.z), 0.0f, 0.0f,
							   sin(rotation.z), cos(rotation.z), 0.0f, 0.0f,
							   0.0f, 0.0f, 1.0f, 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f   };
return mul(rotateY, mul(rotateX, rotateZ));
}

GeometryVSOut GeometryVS(GeometryVSIn input)
{
	GeometryVSOut output;
	output.position.x += input.instancePosition.x;
	output.position.y += input.instancePosition.y;
	output.position.z += input.instancePosition.z;
float4x4 rotationMatrix = RotateV2M(input.instanceRotation);
	output.position	 = mul(float4(input.position, 1.0f), mul(worldViewProjectionMatrix, rotationMatrix));
	output.positionView = mul(float4(input.position, 1.0f), mul(worldViewMatrix, rotationMatrix).xyz;
	output.normal	   = mul(float4(input.normal, 0.0f), mul(worldViewMatrix, rotationMatrix)).xyz;
	output.texCoord	 = input.texCoord;
  
	return output;
}





So the problem is in the last function(the main vertex shader one),it somehow has trouble converting from float3 to float4 I think,I'm actualy new to the .xyz functionality,I think it's called swizzling.Maybe I'm not implementing the swilling properly?

#1mrheisenberg

Posted 11 September 2012 - 11:23 AM

I get error X3018: invalid subscript 'xyz' when I try to compile my vertex shader.Here is my shader code:

cbuffer PerFrameConstants : register(b0)
{
    float4x4 worldViewProjectionMatrix;
    float4x4 worldViewMatrix;
    float4x4 viewProjectionMatrix;
    float4x4 projectionMatrix;
    float4 cameraNearFar;
    uint4 framebufferDimensions;
    float tessellationFactor;
    float3 padding;
};

struct GeometryVSIn
{
    float3 position : position;
    float3 normal   : normal;
    float2 texCoord : texCoord;
    float3 instancePosition : instancePosition;
    float3 instanceRotation : instanceRotation;
};
struct GeometryVSOut
{
    float4 position	 : SV_Position;
    float3 positionView : positionView;
    float3 normal	   : normal;
    float2 texCoord	 : texCoord;
};


float4x4 RotateV2M(float3 rotation)
{
float4x4 rotateX = { 1.0f, 0.0f, 0.0f, 0.0f,
							   0.0f, cos(rotation.x), -sin(rotation.x), 0.0f,
							   0.0f, sin(rotation.x), cos(rotation.x), 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f  };
float4x4 rotateY = { cos(rotation.y), 0.0, sin(rotation.y), 0.0f,
							   0.0f, 1.0f, 0.0f, 0.0f,
							   -sin(rotation.y), 0.0, cos(rotation.y), 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f   };
float4x4 rotateZ = { cos(rotation.z), -sin(rotation.z), 0.0f, 0.0f,
							   sin(rotation.z), cos(rotation.z), 0.0f, 0.0f,
							   0.0f, 0.0f, 1.0f, 0.0f,
							   0.0f, 0.0f, 0.0f, 1.0f   };
return mul(rotateY, mul(rotateX, rotateZ));
}

GeometryVSOut GeometryVS(GeometryVSIn input)
{
    GeometryVSOut output;
    output.position.x += input.instancePosition.x;
    output.position.y += input.instancePosition.y;
    output.position.z += input.instancePosition.z;
float4x4 rotationMatrix = RotateV2M(input.instanceRotation);
    output.position	 = mul(float4(input.position, 1.0f), mul(worldViewProjectionMatrix, rotationMatrix));
    output.positionView = mul(float4(input.position, 1.0f), mul(worldViewMatrix, rotationMatrix).xyz;
    output.normal	   = mul(float4(input.normal, 0.0f), mul(worldViewMatrix, rotationMatrix)).xyz;
    output.texCoord	 = input.texCoord;
   
    return output;
}





So the problem is in the last function(the main vertex shader one),it somehow has trouble converting from float3 to float4 I think,I'm actualy new to the .xyz functionality,I think it's called swizzling.Maybe I'm not implementing the swilling properly?

PARTNERS