?
Hallo,
ich muss mich ma an euch wenden, ich habe das mit den domain und hullshader anscheinend noch nicht ganz verstanden...
Ich bekomme wenn ich compiliere einen blackscreen und eine Meldung:
"Der Anzeigetreiber wurde nach einem Fehler wiederhergestellt" +
Microsoft C++-Ausnahme: _com_error an Speicherposition
Ich kann leider das problem nicht eingrenzen...was führt zu so einer Meldung?
Daher muss ich euch leider mit code erschlagen, hier einmal die Shader.
Darstellen soll das ganze nen Lightshader:)
////////////////////////////////////////////////////////////////////////////////
// [b]Vertex Shader[/b]
////////////////////////////////////////////////////////////////////////////////
struct VertexInputType
{
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
struct HullInputType
{
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
HullInputType LightVertexShader(VertexInputType input)
{
HullInputType output;
output.position =input.position;
output.tex =input.tex;
output.normal =input.normal;
return output;
}
////////////////////////////////////////////////////////////////////////////
// [b]Hull Shader[/b]
///////////////////////////////////////////////////////////////////////////
cbuffer TessellationBuffer
{
float tessellationAmount;
float3 padding;
};
struct HullInputType
{
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
};
struct ConstantOutputType
{
float edges[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
struct HullOutputType
{
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
};
ConstantOutputType LightPatchConstantFunction(InputPatch<HullInputType, 3> inputPatch, uint patchId : SV_PrimitiveID)
{
ConstantOutputType output;
// Set the tessellation factors for the three edges of the triangle.
output.edges[0] = tessellationAmount;
output.edges[1] = tessellationAmount;
output.edges[2] = tessellationAmount;
// Set the tessellation factor for tessallating inside the triangle.
output.inside = tessellationAmount;
return output;
}
[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("LightPatchConstantFunction")]
HullOutputType LightHullShader(InputPatch<HullInputType, 3> patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
HullOutputType output;
// Set the position for this control point as the output position.
output.position = patch[pointId].position.xyz;
output.tex = patch[pointId].tex.xy;
output.normal = patch[pointId].normal.xyz;
output.viewDirection = patch[pointId].viewDirection;
return output;
}
////////////////////////////////////////////////////////////
// [b]Domain Shader[/b]
////////////////////////////////////////////////////////////
cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};
cbuffer CameraBuffer
{
float3 cameraPosition;
float padding;
};
struct ConstantOutputType
{
float edges[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
struct HullOutputType
{
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
};
[domain("tri")]
PixelInputType LightDomainShader( ConstantOutputType input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<HullOutputType, 3> patch)
{
PixelInputType output;
float3 worldPosition;
float3 normals;
// Determine the position of the new vertex.
worldPosition = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;
normals = uvwCoord.x * patch[0].normal + uvwCoord.y * patch[1].normal + uvwCoord.z * patch[2].normal;
output.tex = uvwCoord.x * patch[0].tex + uvwCoord.y * patch[1].tex + uvwCoord.z * patch[2].tex;
// Calculate the position of the new vertex against the world, view, and projection matrices.
output.position = mul(float4(worldPosition, 1.0f), worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
output.normal = normalize(normals);
// Determine the viewing direction based on the position of the camera and the position of the vertex in the world.
output.viewDirection = cameraPosition.xyz - worldPosition.xyz;
// Normalize the viewing direction vector.
output.viewDirection = normalize(output.viewDirection);
return output;
}
Am Pixel Shader solltes eigentlich nicht liegen aber der vollständigkeit wegen:
///////////////////////////////////////////////////////////////////////
//[b]Pixel Shader[/b]
/////////////////////////////////////////////////////////////////////////
Texture2D shaderTexture;
SamplerState SampleType;
cbuffer LightBuffer
{
float4 ambientColor;
float4 diffuseColor;
float3 lightDirection;
float specularPower;
float4 specularColor;
};
//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
};
float4 LightPixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float3 lightDir;
float lightIntensity;
float4 color;
float3 reflection;
float4 specular;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
// Set the default output color to the ambient light value for all pixels.
color = ambientColor;
// Initialize the specular color.
specular = float4(0.0f, 0.0f, 0.0f, 0.0f);
// Invert the light direction for calculations.
lightDir = -lightDirection;
// Calculate the amount of light on this pixel.
lightIntensity = saturate(dot(input.normal, lightDir));
if(lightIntensity > 0.0f)
{
// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
color += (diffuseColor * lightIntensity);
// Saturate the ambient and diffuse color.
color = saturate(color);
// Calculate the reflection vector based on the light intensity, normal vector, and light direction.
reflection = normalize(2 * lightIntensity * input.normal - lightDir);
// Determine the amount of specular light based on the reflection vector, viewing direction, and specular power.
specular = pow(saturate(dot(reflection, input.viewDirection)), specularPower);
}
// Multiply the texture pixel and the input color to get the textured result.
color = color * textureColor;
// Add the specular component last to the output color.
color = saturate(color + specular);
return color;
}
Einiges davon ist zusammen gepasted,dewegen die englischen Kommmentare.
Nicht die feine Art,aber i-wie muss man ja ma nen ersten Einblick von der Sache bekommen..
Würde das Problem gerne eingrenzen...
Würde mich über einwenig hilfe sehr freuen!
Euer shadergirl