সম্ভাব্য টেক্সচার এবং স্থগিত আলো


10

ইন আমার আগের প্রশ্ন , আমি জিজ্ঞাসা করলাম কিনা তা পিছিয়ে আলো প্রক্ষিপ্তভাবে টেক্সারিং না করা সম্ভব। এখন (অর্ধ বছরেরও বেশি পরে) আমার একই জিনিসটি বাস্তবায়নে আমার সমস্যা আছে। আমি এই কৌশলটি হালকা পাসে প্রয়োগ করার চেষ্টা করছি। (আমার প্রজেক্টর আলবেডোকে প্রভাবিত করে না)। আমার এই প্রজেক্টরটি একটি প্রজেকশন ম্যাট্রিক্স দেখুন:

Matrix projection = Matrix.CreateOrthographicOffCenter(-halfWidth * Scale, halfWidth * Scale, -halfHeight * Scale, halfHeight * Scale, 1, 100000);
Matrix view       = Matrix.CreateLookAt(Position, Target, Vector3.Up);

যেখানে halfWidthএবং halfHeightজমিনের প্রস্থ এবং উচ্চতার অর্ধেক, Positionসেখানে প্রজেক্টরের অবস্থান এবং targetপ্রজেক্টরের লক্ষ্য। এটা ঠিক আছে বলে মনে হচ্ছে। আমি এই শেডার দিয়ে পূর্ণ স্ক্রিন কোয়াড আঁকছি:

float4x4 InvViewProjection;

texture2D DepthTexture;
texture2D NormalTexture;
texture2D ProjectorTexture;

float4x4 ProjectorViewProjection;

sampler2D depthSampler = sampler_state {
    texture = <DepthTexture>;
    minfilter = point;
    magfilter = point;
    mipfilter = point;
};

sampler2D normalSampler = sampler_state {
    texture = <NormalTexture>;
    minfilter = point;
    magfilter = point;
    mipfilter = point;
};

sampler2D projectorSampler = sampler_state {
    texture = <ProjectorTexture>;
    AddressU  = Clamp;
    AddressV  = Clamp;
};

float viewportWidth;
float viewportHeight;

// Calculate the 2D screen position of a 3D position
float2 postProjToScreen(float4 position) {
    float2 screenPos = position.xy / position.w;
    return 0.5f * (float2(screenPos.x, -screenPos.y) + 1);
}

// Calculate the size of one half of a pixel, to convert
// between texels and pixels
float2 halfPixel() {
    return 0.5f / float2(viewportWidth, viewportHeight);
}

struct VertexShaderInput {
    float4 Position : POSITION0;
};

struct VertexShaderOutput {
    float4 Position :POSITION0;
    float4 PositionCopy : TEXCOORD1;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input) {
    VertexShaderOutput output;
    output.Position = input.Position;
    output.PositionCopy=output.Position;
    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 {
    float2 texCoord =postProjToScreen(input.PositionCopy) + halfPixel();

    // Extract the depth for this pixel from the depth map
    float4 depth = tex2D(depthSampler, texCoord);
    //return float4(depth.r,0,0,1);
    // Recreate the position with the UV coordinates and depth value
    float4 position;
    position.x = texCoord.x * 2 - 1;
    position.y = (1 - texCoord.y) * 2 - 1;
    position.z = depth.r;
    position.w = 1.0f;

    // Transform position from screen space to world space
    position = mul(position, InvViewProjection);
    position.xyz /= position.w;
    //compute projection
    float3 projection=tex2D(projectorSampler,postProjToScreen(mul(position,ProjectorViewProjection)) + halfPixel());
    return float4(projection,1);
}

পিক্সেল শেডারের প্রথম অংশে জি-বাফার থেকে অবস্থানটি পুনরুদ্ধার করা হয়েছে (এই কোডটি আমি কোনও সমস্যা ছাড়াই অন্যান্য ছায়ায়াতে ব্যবহার করছি) এবং তারপরে প্রজেক্টর ভিউপ্রজেকশন স্পেসে ট্রান্সফর্ম করা হয়। সমস্যা হ'ল প্রক্ষেপণটি উপস্থিত হয় না। এখানে আমার পরিস্থিতি একটি চিত্র:

সমস্যার চিত্র

সবুজ লাইনগুলি রেন্ডার্ড প্রজেক্টর হতাশ। কোথায় আমার ভুল লুকানো আছে? আমি এক্সএনএ ৪ ব্যবহার করছি advice পরামর্শের জন্য ধন্যবাদ এবং আমার ইংরেজিটির জন্য দুঃখিত।

সম্পাদনা করুন:

উপরের শেডার কাজ করছেন তবে অভিক্ষেপটি খুব ছোট ছিল। যখন আমি স্কেল সম্পত্তিটি একটি বড় মান (উদাহরণস্বরূপ 100) এ পরিবর্তন করি, তখন অভিক্ষেপ উপস্থিত হয়। কিন্তু যখন ক্যামেরাটি প্রক্ষেপণের দিকে এগিয়ে যায়, তখন এই ইউটিউব ভিডিওতে দেখা যায় মৌমাছি হিসাবে দেখা যায়, প্রক্ষেপণটি প্রসারিত হয় ।

উত্তর:


5

আপনার শেডারে আপনাকে position.xyz /= w;পুনরায় আকার পরিবর্তন করার সমস্যার কারণ এটিই সরিয়ে ফেলতে হবে :

// Transform position from screen space to world space 
position = mul(position, InvViewProjection); 
position.xyz /= position.w;  <<-- Comment this out

কৌতুক করা উচিত।


0

যদি আপনি খুব ছোট ফলাফল পেয়ে থাকেন এবং সেই আকারে পান তবে হতাশাগুলি এখনও 1 থেকে -1 স্পেসে বা 0 থেকে 1 বা এর মতই রয়েছে বলে মনে হতে পারে? হ'ল হতাশার চারপাশটি কি আপনার উত্স?

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.