Tôi đang sử dụng Ogre3D làm công cụ đồ họa.Tôi có làm gì sai với chương trình CG này không?
tôi tạo ra một lưới bằng tay mà làm việc tốt, UVs là chính xác và được thiết lập để đại diện cho tọa độ lưới (ví dụ này lưới là 10 x 10)
tôi không làm gì trong chương trình đỉnh và có rất chương trình phân đoạn đơn giản. Tôi đã bao gồm cả hai chương trình cộng với tệp tài liệu để giải thích.
Vấn đề của tôi là ngay cả khi bộ lọc được đặt thành không màu nào dường như không giống như ảnh gốc của tôi (đây chỉ là hình ảnh thử nghiệm đang sử dụng vì tôi gặp sự cố khi tạo texture theo cách thủ công ogre). Nó chỉ ra rằng vấn đề không phải là mã của tôi trong ogre nhưng nhiều khả năng một cái gì đó để làm với một trong hai tập tin tài liệu hoặc các mảnh/đỉnh chương trình.
Tôi cũng đã bao gồm ảnh chụp màn hình của đầu ra ở bên trái và hình ảnh gốc ở bên phải. Trình đổ bóng phân mảnh cũng vẽ một lưới đơn giản trên đầu để tôi có thể đảm bảo rằng các tọa độ tia cực tím đã được truyền qua một cách chính xác. Chúng có vẻ như thế.
Bất kỳ cái nhìn sâu sắc sẽ được nhiều đánh giá cao như tôi thực sự không chắc chắn những gì im làm sai.
tập tin Chất liệu:
// CG Vertex shader definition
vertex_program PlainTexture_VS cg
{
// Look in this source file for shader code
source GameObjStandard.cg
// Use this function for the vertex shader
entry_point main_plain_texture_vp
// Compile the shader to vs_1_1 format
profiles arbvp1
// This block saves us from manually setting parameters in code
default_params
{
// Ogre will put the worldviewproj into our 'worldViewProj' parameter for us.
param_named_auto worldViewProj worldviewproj_matrix
// Note that 'worldViewProj' is a parameter in the cg code.
}
}
// CG Pixel shader definition
fragment_program PlainTexture_PS cg
{
// Look in this source file for shader code
source GameObjStandard.cg
// Use this function for the pixel shader
entry_point main_plain_texture_fp
// Compile to ps_1_1 format
profiles arbfp1
}
material PlainTexture
{
// Material has one technique
technique
{
// This technique has one pass
pass
{
// Make this pass use the vertex shader defined above
vertex_program_ref PlainTexture_VS
{
}
// Make this pass use the pixel shader defined above
fragment_program_ref PlainTexture_PS
{
}
texture_unit 0
{
filtering none
// This pass will use this 2D texture as its input
texture test.png 2d
}
texture_unit 1
{
texture textureatlas.png 2d
tex_address_mode clamp
filtering none
}
}
}
}
CG File:
void main_plain_texture_vp(
// Vertex Inputs
float4 position : POSITION, // Vertex position in model space
float2 texCoord0 : TEXCOORD0, // Texture UV set 0
// Outputs
out float4 oPosition : POSITION, // Transformed vertex position
out float2 uv0 : TEXCOORD0, // UV0
// Model Level Inputs
uniform float4x4 worldViewProj)
{
// Calculate output position
oPosition = mul(worldViewProj, position);
// Simply copy the input vertex UV to the output
uv0 = texCoord0;
}
void main_plain_texture_fp(
// Pixel Inputs
float2 uv0 : TEXCOORD0, // UV interpolated for current pixel
// Outputs
out float4 color : COLOR, // Output color we want to write
// Model Level Inputs
uniform sampler2D Tex0: TEXUNIT0,
uniform sampler2D Tex1: TEXUNIT1) // Texture we're going to use
{
//get the index position by truncating the uv coordinates
float2 flooredIndexes = floor(uv0);
if((uv0.x > 0.9 && uv0.x < 1.1)
|| (uv0.x > 1.9 && uv0.x < 2.1)
|| (uv0.x > 2.9 && uv0.x < 3.1)
|| (uv0.x > 3.9 && uv0.x < 4.1)
|| (uv0.x > 4.9 && uv0.x < 5.1)
|| (uv0.x > 5.9 && uv0.x < 6.1)
|| (uv0.x > 6.9 && uv0.x < 7.1)
|| (uv0.x > 7.9 && uv0.x < 8.1)
|| (uv0.x > 8.9 && uv0.x < 9.1)) {
float4 color1 = {1.0,0,0,0};
color = color1;
} else if((uv0.y > 0.9 && uv0.y < 1.1)
|| (uv0.y > 1.9 && uv0.y < 2.1)
|| (uv0.y > 2.9 && uv0.y < 3.1)
|| (uv0.y > 3.9 && uv0.y < 4.1)
|| (uv0.y > 4.9 && uv0.y < 5.1)
|| (uv0.y > 5.9 && uv0.y < 6.1)
|| (uv0.y > 6.9 && uv0.y < 7.1)
|| (uv0.y > 7.9 && uv0.y < 8.1)
|| (uv0.y > 8.9 && uv0.y < 9.1)) {
float4 color1 = {1.0,0,0,0};
color = color1;
} else {
//get the colour of the index texture Tex0 at this floored coordinate
float4 indexColour = tex2D(Tex0, (1.0/10)*flooredIndexes);
color = indexColour;
}
}
Cảm ơn để chỉnh sửa, tôi wasnt chắc chắn làm thế nào để đưa hình ảnh trong :) –
thay đổi 'float4 indexColour = tex2D (Tex0, (1.0/10) * flooredIndexes); 'cho' float4 indexColour = tex2D (Tex0, (1.0/20) * flooredIndexes); 'có thể giải quyết vấn đề – hamed
Không chắc chắn nếu điều đó đã giúp hay không, nó không giải quyết được vấn đề. Lý do tôi nhân với 1/10 là vì các chỉ số trong uv0 hiện đang chạy từ 0 - 10 theo cả hướng u và v. Tôi sàn giá trị này vì nội suy của nó trong chương trình phân đoạn nên tôi nhận được các giá trị như 5.6, nếu tôi sàn giá trị này tôi nhận được 5 chia cho số chiều rộng của gạch (10) cho tôi tọa độ cực tím, 0,5 –