GithubHelp home page GithubHelp logo

visualgmq / rs-cpurenderer Goto Github PK

View Code? Open in Web Editor NEW
56.0 56.0 4.0 3.31 MB

a cpu/gpu soft renderer in rust

Rust 100.00%
graphics rasterization rasterizer rendering rust soft-renderer software-renderer

rs-cpurenderer's Introduction

Hi,看这里 👋

我是VisualGMQ,一个游戏开发新手

  • 🔭 目前在中国杭州,从事游戏开发相关工作
  • 🌱 会一些Vulkan。沉浸于游戏引擎开发和游戏开发
  • 💻 用的最多的语言是C++ Badge,这里是我的一些项目:
    • gecs:C++17 ECS框架,源码借鉴EnTT,API设计借鉴Bevy
    • mirrow:C++17 模板元编程框架,含有静态/动态反射和自动序列化功能
    • rs-cpurenderer:使用rust编写的软渲染
    • NickelEngine:C++17,基于ECS的游戏引擎(施工中)

Top Langs

Anurag's GitHub stats

Harlok's wakatime stats

rs-cpurenderer's People

Contributors

visualgmq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rs-cpurenderer's Issues

image.rs中DepthAttachment的初始值问题

impl PureElemImage<f32> {
    pub fn new(w: u32, h: u32) -> Self {
        Self {
            data: vec![std::f32::MAX; (w * h) as usize],
            w,
            h,
        }
    }

我理解的应该是看向Z的负方向,z值越大离相机越近(renderer.rs中深度测试也是保留深度大的值)。

            if depth_attachment.get(x, y) <= z {
                let mut attr = vertex.attributes;
                shader::attributes_foreach(&mut attr, |value| value * z);
                // call pixel shading function to get shading color
                let color = shading(&vertex.attributes, uniforms, texture_storage);
                color_attachment.set(x, y, &color);
                depth_attachment.set(x, y, z);
            }

那么初始值是否应该被设置为浮点最小值?(cpu_renderer.rsgpu_renderer.rs中的clear_depth也是这么做的)。

    fn clear_depth(&mut self) {
        self.depth_attachment.clear(f32::MIN);
    }

Frustum中GPU的矩阵问题

// camera.rs
mpl Frustum {
    #[rustfmt::skip]
    pub fn new(near: f32, far: f32, aspect: f32, fovy: f32) -> Self {

// ...

            } else { // when in GPU, [we use opengl matrix](http://www.songho.ca/opengl/gl_projectionmatrix.html)
                let half_w = near * fovy.tan();
                let half_h = half_w / aspect;
                let near = near.abs();
                let far = far.abs();
                // with far plane, clamp x,y,z in [-1, 1]
                math::Mat4::from_row(&[
                    near / half_w,           0.0,                       0.0,                             0.0,
                              0.0, near / half_h,                       0.0,                             0.0,
                              0.0,           0.0, far + near / (near - far), 2.0 * far * near / (near - far),
                              0.0,           0.0,                      -1.0,                             0.0,
                ])

请问第三行第三列是否应该是(far + near) / (near - far)?

四元数的逆

    pub fn inverse(&self) -> Quaternion {
        self.conjugate() / self.length()
    }

是不是应该为self.conjugate() / self.length_square() ?

Cohen-Sutherland线段裁剪算法

            if outcode & TOP != 0 {
                // 这里是不是应该为 p.x = pt1.x + (pt2.x - pt1.x) * (rect_max.y - pt1.y) / (pt2.y - pt1.y);
                p.x = p1.x + (pt2.x - pt1.x) * (rect_max.y - pt1.y) / (pt2.y - pt1.y);
                p.y = rect_max.y;
            } else if outcode & BOTTOM != 0 {
                // 这里是不是应该为 p.x = pt1.x + (pt2.x - pt1.x) * (rect_min.y - pt1.y) / (pt2.y - pt1.y);
                p.x = p1.x + (pt2.x - pt1.x) * (rect_min.y - pt1.y) / (pt2.y - pt1.y);
                p.y = rect_min.y;
            } else if outcode & RIGHT != 0 {
                p.y = pt1.y + (pt2.y - pt1.y) * (rect_max.x - pt1.x) / (pt2.x - pt1.x);
                p.x = rect_max.x;
            } else if outcode & LEFT != 0 {
                p.y = pt1.y + (pt2.y - pt1.y) * (rect_min.x - pt1.x) / (pt2.x - pt1.x);
                p.x = rect_min.x;
            }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.